I'm having some trouble getting TestFx working with Oracle's JavaFx HelloWorld app:
public class HelloWorld extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World!");
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.show();
}
}
TestFx junit test:
class MyTest extends GuiTest {
public Parent getRootNode() {
return nodeUnderTest;
}
What should nodeUnderTest
be for this example?
StackPane
creation, button action listeners, etc to the constructor and made theStackPane
a private field for the class so it would be available forgetRootNode()
while leaving any code for theprimaryStage
instart()
and it is working now. – Corbel