【发布时间】:2019-12-15 10:41:34
【问题描述】:
我必须使用JavaFx GUI 测试一些Spring 应用程序。不幸的是,我无法将它们一个一个地运行在一起。我正在使用Java 11、JUnit 5.3 和TestFX 库。
我尝试添加如下方法:
@Before
public void setUp() throws Exception
{
System.setProperty("spring.profiles.active", "test");
launch(Main.class);
}
虽然它会再次重新启动应用程序并正常工作。不幸的是,只有一个测试以正确的方式开始并执行。在其他情况下,我会收到错误:
java.util.concurrent.ExecutionException: org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [HikariDataSource (HikariPool-2)] with key 'dataSource'; nested exception is javax.management.InstanceAlreadyExistsException: com.zaxxer.hikari:name=dataSource,type=HikariDataSource
整个测试类现在看起来像这样:
@Before
public void setUp() throws Exception
{
System.setProperty("spring.profiles.active", "test");
launch(Main.class);
}
@Override
public void start(Stage stage) throws Exception {
stage.show();
}
@Test
public void testRegisterButton()
{
clickOn("#register_button");
}
@Test
public void testLoginButton()
{
sleep(200L);
}
}
这里只是一个简单的示例测试。以前我做的
init() 函数没有@Before,只有启动方法。
【问题讨论】:
标签: java spring-boot testing javafx junit