【问题标题】:can't run multiple tests with adb无法使用 adb 运行多个测试
【发布时间】:2015-11-12 18:11:31
【问题描述】:

我可以使用以下命令单独运行我的测试:

C:\Google Drive\Testing>adb -s C4F12CC05723D6E shell am instrument -w -e class c
om.example.project.test.testcases.basictests.Test1 com.example.
project.test/android.support.test.runner.AndroidJUnitRunner

com.example.project.test.testcases.basictests.test1:.

Time: 23.807

OK (1 test)

但我无法运行套件中的所有测试:

C:\Google Drive\Testing>adb -s C4F12CC05723D6E shell am instrument -w com.example
.project.test/android.support.test.runner.AndroidJUnitRunner


Time: 0

OK (0 tests)

我在尝试运行一组测试时得到了相同的结果。

跑步者似乎没有抱怨什么,它只是认为有0个测试,当有几个时。

我在 android studio 中运行测试时遇到了同样的问题,我可以运行单个测试,但不能运行完整套件或完整包。

我正在使用 espresso 2,它使用 AndroidJUnitRunner。

测试包与正在测试的应用程序在同一个项目中。包括主要活动在内的核心应用活动位于 com.example.project 中,测试包是它的子包; com.example.project.test

我该如何调查这个问题?

【问题讨论】:

    标签: android testing command-line adb android-espresso


    【解决方案1】:

    我自己想通了。

    我的问题尤其是我的 android 项目的结构,测试包位置导致运行程序无法找到我的测试,我将它们移至 src/androidTest/java/test,现在我可以运行完整的套件和完整的测试包。

    【讨论】:

      【解决方案2】:

      在尝试运行套件时,您似乎没有提供测试类。

      根据Android documentation

      要运行 UnitTests 类中的所有测试,请输入:

      $ adb shell am 仪器 -w \ -e 类 com.android.demo.app.tests.UnitTests \ com.android.demo.app.tests/android.test.InstrumentationTestRunner

      您还可以运行测试类的子集和组合的整个类。

      要运行 UnitTests 中的所有测试,以及 FunctionTests 中的 testCamera 方法,请输入:

      $ adb shell am 仪器 -w \ -e 类 com.android.demo.app.tests.UnitTests,com.android.demo.app.tests.FunctionTests#testCamera \ com.android.demo.app.tests/android.test.InstrumentationTestRunner

      【讨论】:

      • 问题中提到,我运行单个测试类没有问题,请看第一个代码sn -p。我的测试套件对我有用的唯一方法是能够按顺序运行所有测试,根据官方 android 文档,这是通过第二个代码 sn-p 中的命令完成的,请参阅“运行整个测试包”在文档中。该命令运行,但从未看到我的测试,它每次返回 0 个测试。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-02
      • 1970-01-01
      • 2022-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多