/TestFX

Simple and clean testing for JavaFX.

Primary LanguageJavaOtherNOASSERTION

TestFX

Travis CI AppVeyor Build Status Coveralls Test Coverage Bintray JCenter Maven Central Chat on Gitter

Simple and clean testing for JavaFX.

Status

Version 4 is in alpha phase. Release notes are listed in CHANGES.md. Javadocs are available online (these are auto-generated from master) or by running gradle javadoc.

Features

  • A fluent and clean API.
  • Flexible setup and cleanup of JavaFX test fixtures.
  • Simple robots to simulate user interactions.
  • Rich collection of matchers to verify expected states.

Support for:

  • Java 8 features and JavaFX 8 controls.
  • Multiple testing frameworks (Junit 4, Junit 5, and Spock) with Hamcrest matchers.
  • Precise screenshots of failed tests.
  • Headless testing using Monocle.

Example

The following example application is written for JUnit 4 only. Here is an example of a test with testfx-junit5.

public class DesktopPaneTest extends ApplicationTest {
    @Override
    public void start(Stage stage) {
        Scene scene = new Scene(new DesktopPane(), 800, 600);
        stage.setScene(scene);
        stage.show();
    }

    @Test
    public void should_drag_file_into_trashcan() {
        // given:
        rightClickOn("#desktop").moveTo("New").clickOn("Text Document");
        write("myTextfile.txt").push(ENTER);

        // when:
        drag(".file").dropTo("#trash-can");

        // then:
        verifyThat("#desktop", hasChildren(0, ".file"));
    }
}

Gradle

build.gradle with testfx-core and testfx-junit (Junit4) from Bintray's JCenter (at https://jcenter.bintray.com/):

repositories {
    jcenter()
}

dependencies {
    testCompile "org.testfx:testfx-core:4.0.10-alpha"
    testCompile "org.testfx:testfx-junit:4.0.10-alpha"
}

For Junit5, use the testfx-junit5 artifact instead of testfx-junit

Maven

pom.xml with testfx-core and testfx-junit (Junit4) from Maven Central repository (at https://repo1.maven.org/maven2/).

<dependencies>
    <dependency>
        <groupId>org.testfx</groupId>
        <artifactId>testfx-core</artifactId>
        <version>4.0.10-alpha</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.testfx</groupId>
        <artifactId>testfx-junit</artifactId> <!-- or testfx-junit5 -->
        <version>4.0.10-alpha</version>
        <scope>test</scope>
    </dependency>
</dependencies>

For Junit5, use the testfx-junit5 artifact instead of testfx-junit

Documentation

Motivation

The motivation for creating TestFX was that the existing library for testing JavaFX, Jemmy, was too verbose and unwieldy. We wanted more behavior driven tests with easy-to-read code that our tester could follow and modify on her own.

Today, TestFX is used in all of the about 100 automated GUI tests in LoadUI (video).

Similar Frameworks

  • Jemmy, by the Oracle SQE team.
  • Automaton, a new testing framework that supports JavaFX as well as Swing.
  • MarvinFX, test support for JavaFX Propertys.

Gitter

Head over to our gitter chat for discussion and questions.

Credits

TestFX was initially created by @dainnilsson and @minisu as a part of LoadUI in 2012. Today, it is being extended and maintained by @hastebrot, @Philipp91, @minisu and the other contributors.

License

Copyright 2013-2014 SmartBear Software
Copyright 2014-2017 The TestFX Contributors

Licensed under the EUPL, Version 1.1 or - as soon they will be approved by the
European Commission - subsequent versions of the EUPL (the "Licence"); You may
not use this work except in compliance with the Licence.

You may obtain a copy of the Licence at:
http://ec.europa.eu/idabc/eupl.html

Unless required by applicable law or agreed to in writing, software distributed
under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the Licence for the
specific language governing permissions and limitations under the Licence.