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
3
votes
1 answer

How to test multiple scenes in TestFX

I wrote a unit test for ArithmeticProblem class in TestFX. public class ArithmeticProblemTextFx extends TestFxBase { @Test(expected = FxRobotException.class) public void fxIdNotExist() { clickOn("#test123"); } @Test …
user6590187
  • 55
  • 11
3
votes
1 answer

TornadoFX with TestFX close the View after every TestCase

I am trying to test a basic loginscreen (created using tornadofx) with the testfx framework. I have added 3 test cases which runs fine but the problem is they use the previous stage rather than creating a new one. I want the testcases to run…
niteesh
  • 329
  • 3
  • 12
3
votes
3 answers

JavaFX + maven + TestFX + monocle don't work together

I have a small project for demonsration JavaFX + TestFX under maven. I use: Java(TM) SE Runtime Environment (build 1.8.0_40-b26) Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T21:29:23+04:00) Full source:…
Yuriy Alevohin
  • 941
  • 7
  • 18
2
votes
0 answers

TestFX Error: Unit Test Package is not Exported to org.testfx.junit5

When attempting to run a unit test for a GUI button using TestFX, I get an error message from the @Start class. Unable to make public void com.candle.fileexplorertest.view.DirectoryButtonControllerTests.start(javafx.stage.Stage) accessible: module…
2
votes
0 answers

Why can I not run all tests but can run individual tests with testfx and gradle

I have a TornadoFX application and before I added any TestFX tests, all my tests ran fine. Then I added a TestFX test and no tests are run when I run all tests. I can run the TestFX test by itself, or any other test, but not when I just run all…
vextorspace
  • 934
  • 2
  • 10
  • 25
2
votes
1 answer

How to mock methods in a controller that's being tested with TestFX?

Here is a snippet of what a test looks like for TestFX, pulled directly from their GitHub README: @ExtendWith(ApplicationExtension.class) class ClickableButtonTest_JUnit5Hamcrest { private Button button; /** * Will be called with…
notacorn
  • 3,526
  • 4
  • 30
  • 60
2
votes
1 answer

IllegalAccessError when trying to use TestFX caused by module-info.java file

I created a weather application in Java11 using JavaFX (from Maven). Now I'm writing some test code. I want to test some GUI features like "show error message when city name invalid", that's why I want to use TestFX. The problem is I get the error…
2
votes
1 answer

Testing overriden EventHandler in Java (JavaFx, Spring Boot)

I have been writing a small application in Java using Spring Boot with a JavaFX front end. I'm having trouble working out how to test part of one of the controllers. Specifically, the controller includes some event handling for when the 'confirm' or…
Sophie E
  • 67
  • 5
2
votes
1 answer

Can I test stage buttons or Alert dialog with TestFX and JUnit?

I am doing a test class thats verify some things in my window, and i want to know if i can test stage buttons(like know if the window is resizeable, what happend if i click in close request, ...). Scene scene = new Scene(root); //Stage…
JarssS8
  • 61
  • 1
  • 1
  • 12
2
votes
0 answers

How to unit test a JavaFx property binding?

I am using OpenJFX 13 with a presentation model that has DoubleProperty field that gets updated like this: public class MyPresentationModel { private DoubleProperty batteryLevel = new SimpleDoubleProperty<>(100.0); public void…
Wim Deblauwe
  • 25,113
  • 20
  • 133
  • 211
2
votes
1 answer

TestFX: Test if TextArea contains a certrain text after entering it

I would like to test whether a TextArea has this text after entering a certain text. I use the following code, but get an error message. Test Code: this.clickOn("#descriptionTextArea").write("Text"); verifyThat("#descriptionTextArea",…
Lars
  • 173
  • 5
  • 18
2
votes
0 answers

TestFX: Is there a way to include a modal instance in a stage?

I've been trying to write a test with TestFX to check if a modal is opened, but can't find any methods to do it. Below is a View that has openModal() when the button is clicked class MainView : View("Hello TornadoFX") { override val root =…
Ball Tha
  • 27
  • 1
  • 5
2
votes
0 answers

TestFx headless MonoclePlatformFactory not found

I trying to use JavaFX + Maven + TestFX (with headless) i followed this tutorial JavaFX headless tutorial to enable the test in headless mode. my…
JustinMartinDev
  • 559
  • 2
  • 7
  • 23
2
votes
1 answer

Test passing on TestFX, but not in headless mode

I am using TestFX to test selecting multiple items in a ListView using the Ctrl key, then clicking a button, which generates an alert dialog whose content is based on the items selected. press(KeyCode.CONTROL); clickOn((Node) lookup(hasText("Item…
Ollie
  • 1,641
  • 1
  • 13
  • 31
2
votes
1 answer

lateinit property xxx has not been initialized with TestFX in Kotlin

I am testing JavaFX with TestFX. Here are my codes: MainTest: package com.sample; +import xx; public class MainTest extends Application { @Override public void start(Stage primaryStage) throws Exception{ Parent root =…