I am just getting familiar with Java and JavaFX, and am working on a simple project that tests a JavaFX UI. However, I don't think that I'm initializing the tests correctly, as I'm getting an ExceptionInInitializerError when I instantiate the app object. Here is the relevant part of my test file:
public class AppGuiTest extends ApplicationTest {
private App app = new App();
@Override
public void start(Stage stage) throws Exception {
stage.setScene(app.getScene());
stage.show();
stage.toFront();
}
//tests here
}
It errors out when a label is defined within the app object:
Label message = new Label("Welcome!");
Here is the relevant part of my Gradle file:
plugins {
id 'org.openjfx.javafxplugin' version '0.0.9'
}
dependencies {
implementation 'org.testfx:testfx-junit:4.0.15-alpha'
implementation 'org.loadui:testFx:3.1.2'
implementation 'org.testfx:testfx-junit5:4.0.16-alpha'
implementation 'org.junit.jupiter:junit-jupiter:5.8.1'
implementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
}
javafx {
version = "17"
modules = [ 'javafx.controls' , 'javafx.base']
}
The JavaFX part runs fine by itself. It's only when I try to add the tests that I get the exception. Is this even how I should be initializing things? When I remove the app variable from the test file and comment out the contents of the tests, then the tests pass. If I don't have my app object defined, how do I test the UI elements?
I am not sure what to do to fix this error, so any input would be very helpful. Thanks in advance!