Questions tagged [testfx]

Simple and clean testing for JavaFX.

Simple and clean testing for JavaFX.

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.

Sample:

 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"));
    }
 }

As you can see above, TestFX is emulating GUI action with simple methods like drag(String) or write(String). You are able to call the JavaFX-Components directly via the CSS-ID or CSS-Class string. To call the id you have to add a # before the id, to reach the class you need a . before the classname.

Links:

108 questions
1
vote
0 answers

How should I unit test the main method of a JavaFX program?

Right now, I'm considering incorporating 100% code coverage into my project. However, I'm having trouble unit testing the main entry point of my code: public static void main(String[] args) { launch(args); } This method is difficult to test…
SirMathhman
  • 180
  • 3
  • 11
1
vote
1 answer

Maven and Java Extension

I am trying to build and test a JavaFX application on a headless build server. Locally I am using TestFX and Monocle https://github.com/TestFX/Monocle and its working fine. However, I had to manually install Monocle into the java Extensions folder…
Trevor
  • 995
  • 3
  • 10
  • 25
1
vote
0 answers

Build server + JRE Extensions

I'm looking to build a javaFX app with headless unit-testing with Monocle and Maven. I've been able to get headless testing to work locally with building the monocle jar myself and loading it into my /Extensions java folder as specified here: JavaFX…
Trevor
  • 995
  • 3
  • 10
  • 25
1
vote
1 answer

How to run a test on Travis which uses JavaFX elements?

I want to test a method (also remotely on Travis) which wants as parameter a JavaFX element, for example a ProgressIndicator. But when I make a new ProgressIndicator() in my test method, when I execute the test (with Gradle) it fails on that line…
PHPirate
  • 7,023
  • 7
  • 48
  • 84
1
vote
1 answer

TestFx4 / JavaFx - How to get TableView Cell graphic

I´m trying find out how to get a graphic of a specified cell of a tableView. My scenerio looks like this: I know i can get a value of a specified cell, which would look something like this: getCellValue(TableView table, int column, int row) { …
Mono
  • 206
  • 1
  • 21
1
vote
0 answers

java.util.concurrent.RejectedExecutionException when action calls runAsync

I noticed while updating my TornadoFX version from 1.7.12 to 1.7.14 that one of my tests broke. Things seemed to go off the rails when a runAsyncWithProgress in the View under test was rejected by a ThreadPoolExecutor with status Terminated. I saw…
1
vote
2 answers

Testfx gives java.lang.NoSuchMethodError

I changed my test to TestFx but problem is persist. FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/ILAreaManagement/ILArea.fxml")); Parent root = fxmlLoader.load(); MaintenanceController maintenanceController =…
1
vote
1 answer

How can I prevent duplication in my JavaFX test project

I've got a real simple JavaFX project to teach myself how to write tests with testfx. I can't work out how to prevent myself from having to duplicate my sample.fxml file. The structure of the project is currently: My Main.java looks like…
Return_Of_The_Archons
  • 1,731
  • 3
  • 20
  • 26
1
vote
1 answer

Error when running multiple JavaFx TestFx tests: Caused by: java.lang.IllegalStateException: Cannot set style once stage has been set visible

Have been using the TestFx framework to test my JavaFx app. It runs fine on a test-method by test-method basis. But as soon as I try and run more than one test-method, or test-class at a time, I get this error: Caused by:…
Ben
  • 6,567
  • 10
  • 42
  • 64
1
vote
0 answers

Mockito with testfx

I have an application and connect database with a gateway module. And I write gui tests and I start to use mockito. I try to update an object with open gui. I set combobox, textfield parameters and change them new parameters too but then call save…
1
vote
2 answers

What is fx:id of JavaFX Alert OK Button?

I use TestFX framework for test my javaFX application. I test my application like that : @Test public void shouldClickOnDeletMarkerButton() { FxRobot bot = new FxRobot(); bot.robotContext(); bot.clickOn("#deleteMarkerButton"); …
KaluNight
  • 55
  • 1
  • 9
1
vote
0 answers

TestFX tests pass headful but fail headless

I am trying to write GUI tests for my university project.I am trying to do this using TestFX 4.0.4, but I am having an issue. For the project we are also obliged to use continuous integration with Travis. This means that I have to make the GUI tests…
1
vote
1 answer

In TestFX version 4, how can I wait until an element of the GUI becomes visible?

What Matcher should I use? visible() seems no longer available and unfortunately I could not find an alternative in the org.hamcrest library. Thanks in advance!
Adam Papp
  • 11
  • 4
1
vote
0 answers

First TestFX test executed fails, identical second test passes, when in headless mode

I have a problem with TestFX, and running in headless mode on my desktop PC with openjfx-monocle. Everything was working fine in my first "hobby project" but now when doing this at work I ran into some problems with the main menu that we have. So…
Robert
  • 460
  • 1
  • 5
  • 12
1
vote
0 answers

Cannot run JavaFX in headless environment

In my test package, I have both regular unit tests and testfx test. When I try to run the entire test package, those testfx tests all failed and give the following exception: org.junit.AssumptionViolatedException: Cannot run JavaFX in headless…