0

我正在使用 Junit5 和 TestFX 编写应用程序测试。我的意图是主测试类在每次测试后重新启动应用程序。据我所知,我将使用注释@BeforeEach,它对我不起作用。

这是我的测试课:

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class MainTest extends ApplicationTest implements FxRobotInterface {
Logger loggerGuiTesting = LoggerManager.getInstance().getLogger(LoggerType.GUI_TESTING);

@BeforeEach
@Override
public void start(final Stage stage) {
    StartMain.getInstance();
    this.loggerGuiTesting.log(Level.INFO, "Application starts!");
}

@AfterAll
public void endApplication() {
    new ExitGuiTest().run(); // That's my internal test framework
}

@Test
public void atestIfOpeningScreenIsThere() {
    verifyThat("#imageViewSplashScreenLogo", NodeMatchers.isNotNull());
    verifyThat("#progressBarSplashScreen", NodeMatchers.isNotNull());
    verifyThat("#labelSplashScreenVersion", NodeMatchers.isNotNull());
    verifyThat("#labelSplashScreenDate", NodeMatchers.isNotNull());
    this.loggerGuiTesting.log(Level.INFO, "testIfOpeningScreenIsThere, succeeded!");
}

@Test
public void btestIfRadioButtonOneExist() {
    assertThat("#sourcesOneRadioButton", is("#sourcesOneRadioButton"));
this.loggerGuiTesting.log(Level.INFO, "testIfRadioButtonOneExist, succeeded!");
    }

@Test
    public cnextTest() {
        new StartAnotherGuiTest().run();
        this.loggerGuiTesting.log(Level.INFO, "anotherTest, succeeded!");
    }

}

问题是:如何在每次测试后重新启动应用程序?

4

1 回答 1

1

不看一下 StartMain 类就很难回答。看起来您在那里使用单例模式。如果是这种情况,我将在 StartMain 中创建一个新方法,将单例实例设置为 null,因此当再次调用 getInstance 时,必须重新创建它:

@After //This should be executed after each test
public void destroyApp()
{
    StartMain.getInstance().destroy();
}
于 2019-11-12T09:47:23.003 回答