Fake JavaFX Platform start

ぃ、小莉子 提交于 2019-12-13 01:46:15

问题


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)?

来源:https://stackoverflow.com/questions/32805488/fake-javafx-platform-start

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!