Skip to content

LAP2/TestFX

 
 

Repository files navigation

TestFX

Travis CI Bintray JCenter Maven Center

Simple and clean testing for JavaFX.

Status

Version 4 is in alpha phase. Release notes are listed in CHANGES.md and latest documentation is only available via 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.
  • JUnit testing framework and Hamcrest matchers.
  • Precise screenshots of failed tests.
  • Headless testing using Monocle.

Example

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 and Maven

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

repositories {
    jcenter()
}

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

Gradle build.gradle with testfx-core, testfx-legacy and a different junit version from Maven Central repository (at https://repo1.maven.org/maven2/).

repositories {
    mavenCentral()
}

dependencies {
    testCompile "junit:junit:4.10"
    testCompile "org.testfx:testfx-core:4.0.+"
    testCompile "org.testfx:testfx-legacy:4.0.+", {
        exclude group: "junit", module: "junit"
    }
}

Gradle build.gradle with testfx-core (SNAPSHOT) from Sonatype Snapshots repository (at https://oss.sonatype.org/content/repositories/snapshots/).

repositories {
    mavenCentral()
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}

dependencies {
    testCompile "junit:junit:4.12"
    testCompile "org.testfx:testfx-core:4.0.0-SNAPSHOT"
}

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

<repositories>
    <repository>
        <id>maven-central-repo</id>
        <url>http://repo1.maven.org/maven2</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>org.testfx</groupId>
        <artifactId>testfx-core</artifactId>
        <version>4.0.1-alpha</version>
        <scope>test</scope>
    </dependency>
        <dependency>
            <groupId>org.testfx</groupId>
            <artifactId>testfx-junit</artifactId>
            <version>4.0.1-alpha</version>
            <scope>test</scope>
        </dependency>
</dependencies>

Maven pom.xml with testfx-core (SNAPSHOT) from Sonatype Snapshots repository (at https://oss.sonatype.org/content/repositories/snapshots/).

<repositories>
    <repository>
        <id>maven-central-repo</id>
        <url>http://repo1.maven.org/maven2</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>sonatype-snapshots-repo</id>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        <snapshots>
            <enabled>true</enabled>
       </snapshots>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.testfx</groupId>
        <artifactId>testfx-core</artifactId>
        <version>4.0.0-SNAPSHOT</version>
        <scope>test</scope>
    </dependency>
</dependencies>

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.

Mailing List

Head over to testfx-discuss@googlegroups.com for discussions, questions and announcements.

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-2015 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

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.

About

Simple and clean testing for JavaFX.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%