我正在尝试为我的作曲编写测试。所以我在 AndroidTest 中有一个测试类,就像这样:
@HiltAndroidTest
@UninstallModules(AuthenticationModule::class, AppModule::class)
class AuthenticationScreenTest {
@get:Rule(order = 0)
val hiltRule = HiltAndroidRule(this)
@get:Rule(order = 1)
val composeRule = createAndroidComposeRule<MainActivity>()
@Inject
lateinit var setting: Setting
@Before
fun setup() {
hiltRule.inject()
composeRule.setContent {
val navController = rememberNavController()
RefectoryTheme {
NavHost(
navController = navController,
startDestination = AuthenticationNavGraph.AuthenticationScreen.route
) {
composable(AuthenticationNavGraph.AuthenticationScreen.route) {
AuthenticationScreen(navController = navController, setting = setting)
}
}
}
}
}
@Test
fun checkLoadingButtonExpantion() {
composeRule.onNodeWithTag(testTag = AUTHENTICATION_SCREEN_LOGIN_BUTTON)
.assertIsDisplayed()
}
}
但我不断收到错误:
androidx.compose.ui.test.junit4.android.ComposeNotIdleException: Idling resource timed out:
possibly due to compose being busy.
IdlingResourceRegistry has the following idling resources registered:
- [busy] androidx.compose.ui.test.junit4.ComposeIdlingResource@a005df5
All registered idling resources: Compose-Espresso link
android模拟器启动,测试编译成功,但似乎找不到对象。我还在对象的修饰符中添加了一个测试标签:
LoadingButton(
buttonText = stringResource(id = R.string.login),
isExpanded = state.isLoginExpanded,
modifier = Modifier
.padding(MaterialTheme.spacing.medium)
.align(Alignment.CenterHorizontally)
.testTag(AUTHENTICATION_SCREEN_LOGIN_BUTTON)
) {
viewModel.onEvent(AuthenticationEvent.Login)
}
但是 28 秒后,我得到了上面提到的错误。我错过了什么?