FX-Test: A replacement for TestFX or just another option?

© Shutterstock / fortovik
You might already be familiar with TestFX so you’re probably wondering why FX-Test was created. Well, you should know there are multiple reasons why the latter was created. Keep in mind that there are no releases yet.
There’s a new JavaFX test framework in town! Tom Schindl, Java Champion and CTO of BestSolution, a company specialized in Eclipse and JavaFX consulting for companies around the world revealed in a recent blog post that there are many reasons why FX-Test, a library to implement JUnit-Test for JavaFX applications has been created.
First of all, we decided for now that we don’t integrate the test-framework into e(fx)clipse but treat it as an independent entity at GitHub and release it under EPL from there.
According to the project description, there are at least two reasons why FX-Test was created. First, there are license problems so TestFX can not be used in Eclipse.org projects like e(fx)clipse and second, Test-FX’ bootstrap process is not compatible with e4 OSGi-Applications (although with some tricks it can be done).
SEE ALSO: 20 JavaFX real-world applications
FX-Test overview
The test-framework will not be integrated into e(fx)clipse — at least for now—. Instead, it will be treated as an independent entity at GitHub and released under EPL from there.
Writing JUnit-Tests is done by subclassing a base class (current only one available is FXComponentTest
), Schindl explained in the blog post. Implementing your JUnit-Tests might look like this:
@Test public void sample() { // Search with a css-selector query // and generated a click on the button rcontroller().cssFirst(".button").get().click(); }
Tests written with BestSolution’s API can not run directly, which is why you’ll have to decide if you want to:
- Use a specific runner using
@RunWith(FXRunner.class)
- Use a Rule
@FXTest
and annotate all UI-Test methods with it
This means that the @Test
-methods are executed on the JavaFX-UI-Thread.
Have a look at the project and decide for yourself if you want to give it a shot.