void
void

Reputation: 761

Testing JavaFX application with JUnit

I've got rather simple JavaFX application:

public class Main extends Application {

@Override
public void start(Stage primaryStage) throws Exception {
    final int[] i = {0};
    FlowPane root = new FlowPane();
    root.setPadding(new Insets(40, 40, 40, 40));
    Button btn1 = new Button("Button 1");
    Button btn2 = new Button("Button 2");
    Label lbl = new Label("Output");
    Label lbl1 = new Label("Counter here");

    btn1.setOnAction(event -> { lbl.setText("Button 1 is pressed");
    lbl1.setText(""+ i[0]++);});

    btn2.setOnAction(event -> { lbl.setText("Button 2 is pressed");
        lbl1.setText(""+ i[0]++);});

    root.getChildren().addAll(lbl, btn1, btn2, lbl1);
    root.setId("root");
    primaryStage.setScene(new Scene(root, 100, 150));
    primaryStage.show();
}

public static void main(String[] args) {
    launch(args);
}
}

How can I test it with JUnit framework? What aspects of the app should be tested? I just want to understand how JavaFX applications are usually subjected to test.

Upvotes: 3

Views: 4223

Answers (1)

Branislav Lazic
Branislav Lazic

Reputation: 14826

Well... you can perform various tests. Your choice. Logic is being tested with JUnit. If you application connects to some external system, you can perform integration tests. However, I think that your question is more related about testing JavaFX UI (functional testing) If so, you can use something like a TestFX.

Upvotes: 3

Related Questions