Class ApplicationTest

java.lang.Object
org.testfx.api.FxRobot
org.testfx.framework.junit.ApplicationTest
All Implemented Interfaces:
FxRobotInterface, ApplicationFixture

public abstract class ApplicationTest extends FxRobot implements ApplicationFixture
The base class that your JUnit test classes should extend from that interact with and/or verify the state of a JavaFX UI. Such test classes, containing one or more @Test-annotated methods (individual test cases), can interact with a JavaFX UI using the FxRobot methods that test class will inherit (as it extends ApplicationTest (this class) which extends FxRobot). Verifying the state of the UI can be accomplished by using either the Hamcrest based FxAssert.verifyThat(T, org.hamcrest.Matcher<? super T>) or the AssertJ based Assertions.assertThat(Node).

Example:


 public class ColorSelectorTest extends ApplicationTest {

     Stage stage;
     ColorPicker colorPicker;

     {@literal @}Override
     public void start(Stage stage) throws Exception {
         this.stage = stage;
     }

    {@literal @}Before
     public void beforeEachTest() throws Exception {
         Platform.runLater(() -> {
             colorPicker = new ColorPicker(Color.BLUE);
             StackPane stackPane = new StackPane(colorPicker);
             Scene scene = new Scene(root, 800, 800);
             stage.setScene(scene);
             stage.show();
         });
        WaitForAsyncUtils.waitForFxEvents();
     }

     {@literal @}Test
     public void shouldAllowUserToChangeColor() {
         // when:
         clickOn(colorPicker);
         type(KeyCode.DOWN);
         type(KeyCode.DOWN);

         // then:
         assertThat(colorPicker.getValue()).isEqualTo(Color.TEAL);
     }
 }