如何互动测试桌面多平台Compose(即,非无头)

huangapple go评论58阅读模式
英文:

How to test Compose Multiplatform for Desktop interactively (i.e., not headless)

问题

有没有一种可以交互式地运行带有 androidx.compose.ui.test 的测试的方法(即,以便我可以亲眼看到它们运行)?我遇到了一些问题,如果能够在测试尝试执行时看到UI将会很有帮助。

我尝试添加了一个长时间的 Thread.sleep,以防测试运行得太快,我永远无法看到任何东西,但仍然无法在长时间的休眠中看到UI。

谢谢。

英文:

Is there a way to run tests with androidx.compose.ui.test interactively (i.e., so that I can see them running with my own eyes)? I’m having trouble with something and it would help to be able to see the UI as the test is trying to execute.

I tried adding a long Thread.sleep in case the test was running so quickly I never got to see anything, but still can't see the UI with a long sleep.

Thanks.

答案1

得分: 2

暂时无法在使用androidx.compose.ui.test时查看UI,因为它测试Compose逻辑而不涉及窗口管理。

然而,有一个内部的Compose Desktop API,允许使用Swing窗口管理运行测试。请注意,这个API未正式公开,因为Swing被视为实现细节。尽管如此,你可以尝试通过复制代码(考虑许可证)来使用这种方法,这可能提供了一种查看UI的方式。

英文:

At least for now, it is not possible to see the UI when using androidx.compose.ui.test, since it tests Compose logic without window management.

However, there is an internal Compose Desktop API available that allows running tests with Swing window management. Please note that this API is not officially exposed as Swing is considered an implementation detail. Nevertheless, you can try using this approach by copying the code (taking the license into account). This may provide a way to see the UI.

huangapple
  • 本文由 发表于 2023年5月7日 16:54:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76192964.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定