Blog
Introducing (another/additional) JavaFX TestFramework
Let me start with the statement that TestFX is somewhat the default JUnit-Testframework for JavaFX application and is what we proposed to use to all our customers and our projects until today where we introduce our own one. There are 2 different problem vectors we have:
- A licensing issue we have with it at Eclipse.org: TestFX is licensed under EUPL which to me as a software developer looks ok but it looks like the IP-Department at Eclipse.org is not happy about it and refused me to use it. I don't blame anyone but need to cope with the situation as is!
- Implementing JUnit-Tests for OSGi-JavaFX applications: This is a pure technical issue and something we could have solved (although it would have meant to change the way TestFX works) but after having hit the licensing problem my motivation to resolve that problem was not really there
Anyways let's look at what I've started to implement as a replacement for TestFX.
BestSolution FX-Test
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. Writing JUnit-Tests is done by subclassing a base class (current only one available is FXComponentTest) and 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();
}
In contrast to TestFX, tests written with our API can not run directly but you need to decided if you want to:
- Use a specific runner using
@RunWith(FXRunner.class) - Use a Rule
@FXTestand annotate all UI-Test methods with it
which on the plus-side means that the @Test-methods are executed on the JavaFX-UI-Thread (unlike TestFX where they are executed on another thread most like the main-thread) For more information that a look at the project README.md. Let me close this post saying that we are very early in the development and things are still in the flux so we are happy for any feedback we get.