在单元测试中等待Platform.RunLater

在单元测试中等待Platform.RunLater,第1张

在单元测试中等待Platform.RunLater

我解决的方法如下。

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(...)`

适用于简单测试



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5008552.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-14
下一篇 2022-11-14

发表评论

登录后才能评论

评论列表(0条)

保存