使用Eclipse photon中的testfx4.0.14和fx9或fx11(无所谓)时
simple example test
should_click_on_button()
具有
Expected: Labeled has text "clicked!"
but: was "click me!"
知道怎么了吗?
测试代码(为了方便起见,全部从wiki复制):
import org.junit.Test;
import org.testfx.framework.junit.ApplicationTest;
import static org.testfx.api.FxAssert.*;
import static org.testfx.matcher.control.LabeledMatchers.*;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
/**
* Simple testfx example from testfx wiki:
* https://github.com/TestFX/TestFX/wiki/Getting-Started
*
*/
public class ClickApplicationTest extends ApplicationTest {
@Override
public void start(Stage stage) {
Parent sceneRoot = new ClickApplication.ClickPane();
Scene scene = new Scene(sceneRoot, 100, 100);
stage.setScene(scene);
stage.show();
}
@Test
public void should_contain_button() {
// expect:
verifyThat(".button", hasText("click me!"));
}
@Test
public void should_click_on_button() {
// when:
clickOn(".button");
// then:
verifyThat(".button", hasText("clicked!"));
}
}
import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/**
* Simple testfx example from testfx wiki:
* https://github.com/TestFX/TestFX/wiki/Getting-Started
*
*/
public class ClickApplication extends Application {
// application for acceptance tests.
@Override public void start(Stage stage) {
Parent sceneRoot = new ClickPane();
Scene scene = new Scene(sceneRoot, 100, 100);
stage.setScene(scene);
stage.show();
}
// scene object for unit tests
public static class ClickPane extends StackPane {
public ClickPane() {
super();
Button button = new Button("click me!");
button.setOnAction(actionEvent -> button.setText("clicked!"));
getChildren().add(button);
}
}
}
更新:
TestFX
可能是匹配的。它提到了一个
core fx bug
这可能是原因-但似乎不是:它在fx11中是固定的(验证了核心bug报告中的代码通过了),但是testfx问题占了上风。。