【问题标题】:How to run multiple JavaFX tests?如何运行多个 JavaFX 测试?
【发布时间】:2019-12-15 10:41:34
【问题描述】:

我必须使用JavaFx GUI 测试一些Spring 应用程序。不幸的是,我无法将它们一个一个地运行在一起。我正在使用Java 11JUnit 5.3TestFX 库。

我尝试添加如下方法:

    @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


    【解决方案1】:

    您是否尝试过禁用 JMX 自动配置?

    @Configuration
    @EnableAutoConfiguration(exclude = {
        JmxAutoConfiguration.class
    })
    

    或者

    spring.jmx.enabled = false
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-06
      • 2014-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多