0

我正在尝试为我的作曲编写测试。所以我在 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 秒后,我得到了上面提到的错误。我错过了什么?

4

1 回答 1

0

我才意识到问题出在哪里。我在屏幕上使用 Lottie,动画无限重复。所以我不知道为什么,但似乎它不允许测试通过。当我评论 Lottie 部分时,测试运行没有任何问题。

于 2022-02-13T12:19:39.300 回答