Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) JUnit: Add support classes, including an ApplicationTest base test class. #163

Merged
merged 12 commits into from Mar 4, 2015

Conversation

hastebrot
Copy link
Member

This PR adds some convenience classes for JUnit.

  • It will be within the module testfx-junit.
  • It will include an ApplicationTest class, that will serve as counterpart to JavaFX's Application. It launches the Toolkit per default and inherits methods from FxRobot.
  • It will also include helpful classes for JUnit Categorys and Rules.

@hastebrot hastebrot changed the title feat(JUnit): Add JUnit support classes. (feat) JUnit: Add JUnit support classes. Feb 26, 2015
@hastebrot
Copy link
Member Author

testfx-junit will compile with junit as dependency:

repositories {
    jcenter()
}

dependencies {
    testCompile "org.testfx:testfx-core:4.0.+"
    testCompile "org.testfx:testfx-junit:4.0.+"
}

ApplicationTest is the testing counter-part to Application:

public class HelloWorldDemo extends Application {
    @Override
    public void start(Stage stage) {
        Label label = new Label("Hello World!");
        StackPane root = new StackPane(label);
        Scene scene = new Scene(root, 400, 400);

        stage.setScene(scene);
        stage.show();
    }
}

public class HelloWorldDemoTest extends ApplicationTest {
    @Override
    public void start(Stage stage) {
        Label label = new Label("Hello World!");
        StackPane root = new StackPane(label);
        Scene scene = new Scene(root, 400, 400);

        stage.setScene(scene);
        stage.show();
    }

    @Test
    public void should_contain_label() {
        verifyThat(".label", hasText("Hello World!"));
    }
}

Use FxToolkit for special use-cases:

public class HelloWorldDemoTest extends ApplicationTest {
    @Override
    public void init() throws Exception {
        FxToolkit.registerStage(() -> new Stage());
    }

    @Override
    public void start(Stage stage) {
        Label label = new Label("Hello World!");
        StackPane root = new StackPane(label);
        Scene scene = new Scene(root, 400, 400);

        stage.setScene(scene);
        stage.show();
    }

    @Override
    public void stop() throws Exception {
        FxToolkit.hideStage();
    }

    @Test
    public void should_contain_label() {
        verifyThat(".label", hasText("Hello World!"));
    }
}

ApplicationTest.launch() is the testing counter-part to Application.launch():

public class HelloWorldMain {
    public static void main(String args) {
        Application.launch(HelloWorldDemo.class, args);
    }
}

public class HelloWorldMainTest {
    @Before
    public void setup() throws Exception {
        ApplicationTest.launch(HelloWorldDemo.class);
    }

    @After
    public void cleanup() throws Exception {
        FxToolkit.cleanupStages();
    }

    @Test
    public void should_contain_label() {
        verifyThat(".label", hasText("Hello World!"));
    }
}

… `testfx-junit` dependency to the Gradle section.
@hastebrot hastebrot changed the title (feat) JUnit: Add JUnit support classes. (feat) JUnit: Add support classes, including an ApplicationTest base test class. Mar 2, 2015
hastebrot added a commit that referenced this pull request Mar 4, 2015
(feat) JUnit: Add support classes, including an `ApplicationTest` base test class.
@hastebrot hastebrot merged commit 5646e25 into TestFX:master Mar 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant