【发布时间】:2020-12-30 22:03:28
【问题描述】:
我是 android 测试的新手,不知道这是否会发生。
是否可以使用 androidx.test.ext AndroidJunit4 运行器运行 Jetpack compose 单元测试?
所以我们不需要运行instrumentation 测试和使用设备。
这是我尝试过的:
app/src/test/:
@RunWith(AndroidJUnit4::class)
class ExampleUnitTest {
@get:Rule
val activityScenarioRule = ActivityScenarioRule(MainActivity::class.java)
@get:Rule
val composeTestRule = createAndroidComposeRule<MainActivity>()
// createComposeRule() if you don't need access to the activityTestRule
@Test
fun greeting_showsGreetingText() {
// Start the app
composeTestRule.setContent {
analyzerTheme {
// A surface container using the 'background' color from the theme
Surface(color = MaterialTheme.colors.background) {
Greeting("Android")
}
}
}
composeTestRule.onNodeWithText("Hello Android!").assertIsDisplayed()
}
}
运行测试我得到以下错误:
No tests found for given includes: [greeting_showsGreetingText]
【问题讨论】:
-
如果你想在单元测试中使用 ActivityScenarioRule,我相信你仍然需要使用 Robolectric。
标签: android android-testing android-jetpack-compose