mercredi 7 août 2019

How to run multiple JavaFX tests?

I have to test some Spring application with JavaFx GUI. Unfortunately, I can't run them together, one by one. I'm using Java 11, JUnit 5.3 and TestFX library.

I tried to add methods like:

    @Before
    public void setUp() throws Exception
    {
        System.setProperty("spring.profiles.active", "test");
        launch(Main.class);
    }

and I though it will restart application again and work properly. Unfortunately, just one test starts in a proper way and execute. In other cases I get error:

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

Whole testing class looks now like that:



    @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);
    }
}

There are just a simple example tests. Previous I made init() function without @Before, just with launch method.

Aucun commentaire:

Enregistrer un commentaire