ArithmeticProblem
我在 TestFX 中为类编写了一个单元测试。
public class ArithmeticProblemTextFx extends TestFxBase {
@Test(expected = FxRobotException.class)
public void fxIdNotExist() {
clickOn("#test123");
}
@Test
public void allComponentsShouldHaveRightText() {
verifyThat("#jfxButtonCheck", hasText("PRÜFEN"));
verifyThat("#jfxButtonNextArithmeticProblem", hasText("NÄCHSTE AUFGABE"));
verifyThat("#jfxButtonSave", hasText("SPEICHERN"));
verifyThat("#jfxTextFieldResult", hasText(""));
}
@Test
public void checkTextFieldResult() {
JFXTextField jfxTextFieldResult = find("#jfxTextFieldResult");
JFXButton jfxButtonCheck = find("#jfxButtonCheck");
jfxTextFieldResult.setText("5");
assertFalse(
"Der Button ist darf NICHT disable sein, da eine Zahl in TextFieldResult steht.",
jfxButtonCheck.isDisable()
);
jfxTextFieldResult.setText("g");
assertTrue(
"Der Button muss disable sein, da KEINE Zahl in TextFieldResult steht.",
jfxButtonCheck.isDisable()
);
}
@Test
public void checkJfxButtonSaveClick() {
clickOn("#jfxButtonSave");
verifyThat("#labelTotalResults", hasText("0"));
verifyThat("#labelNumberOfRightResults", hasText("0"));
verifyThat("#labelAmountOfRightResults", hasText("(0%)"));
verifyThat("#labelNumberOfWrongResults", hasText("0"));
verifyThat("#labelAmountOfWrongResults", hasText("(0%)"));
verifyThat("#labelTimePerArithmeticProblem", hasText(""));
verifyThat("#labelMark", hasText("-"));
verifyThat("#labelRightResult", hasText(""));
verifyThat("#jfxTextFieldResult", hasText(""));
}
@Test
public void checkJfxButtonNextArithmeticProblemClick() {
clickOn("#jfxButtonNextArithmeticProblem");
verifyThat("#labelRightResult", hasText(""));
verifyThat("#jfxTextFieldResult", hasText(""));
verifyThat("#labelTimePerArithmeticProblem", hasText(""));
}
}
这是“TestFxBase”的代码
public class TestFxBase extends ApplicationTest {
@Before
public void setUpClass() throws Exception {
ApplicationTest.launch(Main.class);
}
@After
public void afterEachTest() throws TimeoutException {
FxToolkit.hideStage();
release(new KeyCode[]{});
release(new MouseButton[]{});
}
@Override
public void start(Stage stage) throws Exception {
stage.show();
}
public <T extends Node> T find(final String query) {
return (T) lookup(query).queryAll().iterator().next();
}
}
当我加载 Main.class 时,它只显示 ArithmeticProblem-Scene。这是它的外观。
所以我只能测试ArithmeticProblem.class,因为我不知道如何加载其他场景。在我的菜单中,我还有一些其他点,例如评估或设置,我该如何加载这个场景?