Tôi muốn tạo thử nghiệm JUnit cơ bản cho ứng dụng JavaFX 8. Tôi có mẫu mã đơn giản này:Kiểm tra JUnit cơ bản cho JavaFX 8
public class Main extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Tabs");
Group root = new Group();
Scene scene = new Scene(root, 400, 250, Color.WHITE);
TabPane tabPane = new TabPane();
BorderPane borderPane = new BorderPane();
for (int i = 0; i < 5; i++) {
Tab tab = new Tab();
tab.setText("Tab" + i);
HBox hbox = new HBox();
hbox.getChildren().add(new Label("Tab" + i));
hbox.setAlignment(Pos.CENTER);
tab.setContent(hbox);
tabPane.getTabs().add(tab);
}
// bind to take available space
borderPane.prefHeightProperty().bind(scene.heightProperty());
borderPane.prefWidthProperty().bind(scene.widthProperty());
borderPane.setCenter(tabPane);
root.getChildren().add(borderPane);
primaryStage.setScene(scene);
primaryStage.show();
}
}
tôi chỉ có mã này cho đến nay:
import javafx.application.Application;
import javafx.stage.Stage;
import org.junit.BeforeClass;
public class BasicStart extends Application {
@BeforeClass
public static void initJFX() {
Thread t = new Thread("JavaFX Init Thread") {
@Override
public void run() {
Application.launch(BasicStart.class, new String[0]);
}
};
t.setDaemon(true);
t.start();
}
@Override
public void start(Stage primaryStage) throws Exception {
// noop
}
}
Bạn có thể cho tôi biết làm thế nào tôi có thể tạo thử nghiệm JUnit cho mã trên?
tôi sẽ khuyên bạn sử dụng JemmyFX - phải mất một chút thời gian và công sức để thiết lập và làm quen với, nhưng nó là rất mạnh mẽ. Bạn có thể sẽ dành rất nhiều thời gian và công sức để làm một cái gì đó không tốt nếu bạn bắt đầu từ đầu anyway. – assylias