我解决的方法如下。
1)创建一个简单的信号量函数,如下所示:
public static void waitForRunLater() throws InterruptedException { Semaphore semaphore = new Semaphore(0); Platform.runLater(() -> semaphore.release()); semaphore.acquire();}
2)
waitForRunLater()在需要等待时致电。因为
Platform.runLater()(根据javadoc)按照可提交的顺序执行可运行对象,所以您可以在测试中编写:
...commandThatSpawnRunnablesInJavaFxThread(...)waitForRunLater(...)asserts(...)`
适用于简单测试
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)