【问题标题】:Android Studio Testing shows Test results 0/0. How can I begin the tests?Android Studio 测试显示测试结果 0/0。我怎样才能开始测试?
【发布时间】:2023-01-13 06:36:53
【问题描述】:

我正在 Android Studio 中学习 Kotlin 初学者课程 - 在测试阶段,试验结果总是0/0.我怎样才能完成这些测试?

代码由 Google Android 开发人员编写,应该可以完美运行。 (我用的一样)。应用程序编译没有错误。代码在这里: https://github.com/google-developer-training/android-basics-kotlin-words-app

我尝试了各种解决方案:

它可能与 Android Studio 版本 Bumblebee 或模拟器中阻止测试的某些设置有关。我怀疑这一点,因为在创建以前的应用程序时,在测试阶段发生了同样的事情(测试结果 0/0)

测试结果说:

05/04 21:06:18:在 Pixel 3 API 29 上启动“navigate_to_words_...()”。 应用程序重启成功,无需重新安装。 运行测试

$ adb shell am instrument -w -m -e debug false -e class 'com.example.wordsapp.NavigationTests#navigate_to_words_nav_component' com.example.wordsapp.test/android.support.test.runner.AndroidJUnitRunner 连接到设备“Pixel_3_API_29 [emulator-5556]”上的进程 10870。>

你对此有何看法?感谢您的时间!

【问题讨论】:

    标签: android android-studio kotlin testing


    【解决方案1】:

    看看原来的build.gradle——你用错了测试运行器:

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    

    【讨论】:

    • 我相信这对很多人来说都是正确的答案,不幸的是它没有解决我的问题。然而,我确实在使用 Kaspresso 时发现,在 TestCase 构造函数中使用的 Kaspresso 构建器中添加 shell 命令导致了我的问题。无论如何我都会奖励赏金,因为我相信其他人会发现这个答案很有用。谢谢!
    • 对我不起作用,仍然看到 0/0
    【解决方案2】:

    在我的案例中,测试有效,但今天还没有开始。我试过了:

    • 使缓存无效并重新启动,
    • 编辑配置,
    • 更改设置(Java 版本等),
    • 将项目与 Gradle 文件同步,
    • 检查旧的提交并尝试从那里构建,
    • 恢复默认 IDE 设置,
    • 擦除模拟器,
    • 构建一个应用程序。

    然后我启动了应用程序,发现它没有启动(启动时崩溃)。在 Logcat 中,我看到一个错误并尝试解决它。在我的例子中是Didn't find class "androidx.core.app.CoreComponentFactory",但解决方案是https://stackoverflow.com/a/74836005/2914140

    android.useAndroidX=true
    android.enableJetifier=true
    

    gradle.properties

    之后我发现问题是一个糟糕的依赖注入。我修复了它并回复了gradle.properties

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-28
      • 2020-03-28
      • 2017-12-08
      • 2023-01-18
      • 1970-01-01
      • 2022-08-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多