Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
203 lines (164 sloc) 6.4 KB

Build Status


FX-Test is a library to implement JUnit-Test for JavaFX applications

Why FX-Test

FX-Test is similar to TestFX in its purpose but there are multiple reasons why FX-Test has been created:

  • There are License problems hence TestFX can not be used in projects like e(fx)clipse
  • Test-FX' bootstrap process is not compatible with e4 OSGi-Applications (with some trickery you can get it running)

While the 2nd problem could most likely get addressed by contributing to TestFX the first one is an unresolvable blocker and so we are NOT suffering from NIHS.


Plain Java Applications

Testing components

To test components the simplest way is to subclass at.bestsolution.fx.test.junit.FXComponentTest and implement its createComponent method.

Let's suppose you have a LoginComponent like this:

public class LoginComponent {
  private TextField username;
  private PasswordField password;
  private Button login;
  public LoginComponent(BorderPane parent) {
    // ....

You create a subclass of FXComponentTest like this:

public class LoginComponentTest extends FXComponentTesty<BorderPane,LoginComponent> {
  public LoginComponentTest() {

  protected LoginComponent createComponent(BorderPane parent) {
    return new LoginComponent(parent);

And start writing you test methods like this:

public void simpleLoginTest() {

Finally you need to make a choice:

  • You run the complete Test-Class with a specialized JUnit-Runner named at.bestsolution.fx.test.junit.FXRunner
  • You annotate your Test-Methods with @at.bestsolution.fx.test.junit.FXTest

In general we recommend using the FXRunner but eg if you want to use another JUnit-Runner like org.junit.runners.Parameterized the FXTest-Rule is be a handy thing.

See JUnit-Samples for monkey-see-monkey-do example code.


Usage in a maven build requires you to add the an extra repository because there are dependencies on e(fx)clipse projects currently not found in maven-central.

So first step is to add:

      <name>BestSolution e(fx)clipse releases</name>

and now you can add:


e4 on JavaFX Applications

If you use the standard-layout proposed by the e(fx)clipse development team your application structure should look like this:


To start adding JUnit-Tests you create a 5th project and add a pom.xml like this:

<project xmlns="" xmlns:xsi=""
  <name>My e4 app - app junit bundle</name>



To implement the JUnit-Test you subclass at.bestsolution.fx.test.e4.junit.E4JunitTestCase like this:

class ApplicationTest extends E4JunitTestCase {
  public ApplicationTest() {

Now you can start implementing your test methods. See JUnit-Sample for monkey-see-monkey-do example code.

Binary Artifacts


You can grab binary SNAPSHOTS:


Other OpenSource JavaFX TestFrameworks / Tools

  • TestFX - JUnit Test Library similar to FX-Test
  • Jubula - Test Tool with a visual Test-Designer