如何在构建 Android 应用程序时执行 UI Automator 集成测试

发布于 2025-01-15 07:22:35 字数 346 浏览 6 评论 0原文

我已经在我的应用程序中集成了 UI Automator,并且在 Android Studio 中我可以执行 ExampleInstrumentedTest.kt 并执行其中的测试。

当我使用 gradlew 构建应用程序时,我会知道如何执行这些测试,而不仅仅是在运行测试类时。

我已经尝试过这些解决方案:

  • gradlew
  • gradlew test
  • gradlew assembleDebug

但我注意到这些测试没有执行。

另外我想问是否有可能,如果某些测试未通过,构建会失败,或者我无法将测试执行的分支合并到主存储库中。

多谢

I have integrated UI Automator on my app, and in Android Studio I can execute the ExampleInstrumentedTest.kt and the test inside of it are executed.

I would know how can I execute these tests when I build the app with gradlew and not only when I run the test class.

I've tried these solutions:

  • gradlew
  • gradlew test
  • gradlew assembleDebug

But I'm noticing these tests are not executed.

Also I would ask if it's possible that, if some tests are not passed, the build fails or I can't merge the branch the tests are executed into the master repository.

Thanks a lot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终止放荡 2025-01-22 07:22:35

你需要使用浓缩咖啡
测试单个应用的 UI

    dependencies {
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}

@Test
    fun changeText_sameActivity() {
        // Type text and then press the button.
        onView(withId(R.id.editTextUserInput))
                .perform(typeText(stringToBetyped), closeSoftKeyboard())
        onView(withId(R.id.changeTextBt)).perform(click())

        // Check that the text was changed.
        onView(withId(R.id.textToBeChanged))
                .check(matches(withText(stringToBetyped)))
    }

Espresso 代码示例
Espresso 代码示例

You need to use Espresso
Test the UI of a single app

    dependencies {
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}

@Test
    fun changeText_sameActivity() {
        // Type text and then press the button.
        onView(withId(R.id.editTextUserInput))
                .perform(typeText(stringToBetyped), closeSoftKeyboard())
        onView(withId(R.id.changeTextBt)).perform(click())

        // Check that the text was changed.
        onView(withId(R.id.textToBeChanged))
                .check(matches(withText(stringToBetyped)))
    }

Espresso code example
Espresso code example

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文