是否有针对JetBrains @Composable功能的真正乘法测试设置?
我希望能够在我的公共项目的androidTest
目标中获得@composable
上下文,以便测试驻留在CommanMain ,例如ContentLocalProviders和Beatouts。类似:
@Test fun testSomethingComposable() = runComposeTest {
@Composable fun <M> buildMutableState(model: M) { /* ... */ }
assertNotNull { buildMutableState(initialState).value }
}
我以的期望期望fun runcomposetest(content:@composable() - &gt; unit)
commontest
,但只有jvmtest
版本有效。 createComposerule()。setContent {}
androidx提供的功能仅在仪器测试中起作用。
还有其他方法吗?同时,我刚刚将测试推到了jvmtest
,以便我可以向前迈进。
jvmtest
版本:
import androidx.compose.ui.window.application
actual fun runComposeTest(content: @Composable () -> Unit) = runTest {
application(false) {content}
}
但是以下内容在androidTest
中失败:
actual fun runComposeTest(content: @Composable () -> Unit) = runTest {
val rule = createComposeRule()
rule.setContent(content)
}
...出于某种明显的原因。
I'd love to be able to get a @Composable
context running in the androidTest
target of my common project, in order to test higher-order components that reside in commonMain
, such as ContentLocalProviders and layouts. Something like:
@Test fun testSomethingComposable() = runComposeTest {
@Composable fun <M> buildMutableState(model: M) { /* ... */ }
assertNotNull { buildMutableState(initialState).value }
}
I began with expect fun runComposeTest(content: @Composable ()->Unit)
inside of commonTest
, but only the jvmTest
version works. The createComposeRule().setContent {}
function offered by AndroidX only works within an instrumented test.
Any other way around this? Meanwhile, I've just pushed my tests down to jvmTest
so that I can move forward.
The jvmTest
version:
import androidx.compose.ui.window.application
actual fun runComposeTest(content: @Composable () -> Unit) = runTest {
application(false) {content}
}
But the following fails in androidTest
:
actual fun runComposeTest(content: @Composable () -> Unit) = runTest {
val rule = createComposeRule()
rule.setContent(content)
}
... For somewhat obvious reasons.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,他们有一个测试框架,据我所知,文档中没有提及。我添加了a nofollow noreferrer“
但基本上,您希望将
org.jetbrains.com.pose.ui:ui-test-junit4
添加到您的项目中。我正在使用Alpha软件运行:这就是:这些测试当前在Junit5下不起作用,或者我在某个地方阅读(抱歉,没有参考)。因此,请注意显式
kotlin(“ test-junit”)
而不是
“ test”
,它将加载junit5。Turns out they have a test framework that to my knowledge hasn't been announced and receives no mention in the documentation. I added a gist with the full build.gradle.kts.
But basically, you're looking to add
org.jetbrains.compose.ui:ui-test-junit4
to your project. I'm running on alpha software so that's:These tests currently don't work under JUnit5, or so I read somewhere (sorry no reference). Therefore note the explicit
kotlin("test-junit")
instead of
"test"
, which will load junit5.