问题
When I try to perform unit tests on components which contain JavaFX controls I get a java.lang.IllegalStateException: Toolkit not initialized
.
How can components be unit tested which operate with JavaFX controls?
回答1:
Add the following dependency to your project
<dependency>
<groupId>de.saxsys</groupId>
<artifactId>jfx-testrunner</artifactId>
<version>1.2</version>
</dependency>
and the following annotation to your test classes
@RunWith(JfxRunner.class)
回答2:
Just declare and initialize a JFX Panel. Like:
@Test
public void test() throws Exception {
JFXPanel fxPanel = new JFXPanel();
[.. Begin tests ..]
}
It is the easy way...
来源:https://stackoverflow.com/questions/45109876/toolkit-not-initialized-exception-when-unit-testing-an-javafx-application