In my project I have a peculiar setup for testing JavaFX components: First there is an Application that starts the component normally through a main method for visual inspection. But then there are subclasses of this Main classes which are the actual JUnit tests.
In the tests I do not want to run the application with the UI showing up (the tests should also be runnable in a system that has no window manager, e.g. cuntinuous integration). Normally this will throw an error, as the platform is not started. To prevent this, I call:
final Runnable dummyRunnable = new Runnable() {
@Override
public void run() {
System.out.println("Startup platform");
}
};
PlatformImpl.startup(dummyRunnable);
PlatformImpl however is internal API (com.sun.javafx.application.PlatformImpl). Which basically ties the test to a specific brand of JDK. To figure out if this happens I actually call the method through reflection, so I can log the specific error cases.
Is there a way to reach the same thing (running the tests which are a subclass of Application, but do not call the start method, to run in headless mode)?