I deployed a small JUnit TestRunner based on http://awhite.blogspot.de/2013/04/javafx-junit-testing.html into the maven central repository.
You can use it by adding the following dependency to your project:
<dependency> <groupId>de.saxsys</groupId> <artifactId>jfx-testrunner</artifactId> <version>1.0</version> </dependency>
Some JavaFX components does need the JavaFX-Application to be initialized. The TestRunner ensures that you don’t have to mind about an existing JavaFX Application for your Unit Tests. In addition you can choose which test method should be performed in the UI-Thread by using the Annotation @TestInJfxThread
.
@RunWith(JfxRunner.class) public class TestClass { @Test public void testWithoutFXThread() throws Exception { Assert.assertFalse(Platform.isFxApplicationThread()); CompletableFuture isInApplicationThread = new CompletableFuture<>(); Platform.runLater(() -> { isInApplicationThread.complete(Platform.isFxApplicationThread()); }); Assert.assertTrue(isInApplicationThread.get()); } @Test @TestInJfxThread public void testWithFXThread() throws Exception { Assert.assertTrue(Platform.isFxApplicationThread()); } }
Pingback: JavaFX und Spring verbinden und Testen | RoboRally