1

ABD shell正常工作开始仪器测试:

adb shell am instrument de.manayv.lotto.test/android.support.test.runner.AndroidJUnitRunner

为了在未连接到计算机的设备上执行这些测试,我尝试使用以下代码从应用程序(既不是目标应用程序也不是测试应用程序)执行这些测试:

    String packageName = "de.manayv.lotto.noonlinegambling";

    final List<InstrumentationInfo> list = getPackageManager().queryInstrumentation(
                                                                            packageName, 0);
    if  (list.isEmpty()) {
        Toast.makeText(this, "Cannot find instrumentation for " + packageName,
                       Toast.LENGTH_SHORT).show();
        return;
    }

    final InstrumentationInfo instrumentationInfo = list.get(0);
    final ComponentName componentName = new ComponentName(instrumentationInfo.packageName,
                                                          instrumentationInfo.name);

    if (!startInstrumentation(componentName, null, null)) {
        Toast.makeText(this, "Cannot run instrumentation for " + packageName,
                       Toast.LENGTH_SHORT).show();
    }

调试检索以下正确值:

  instrumentationInfo.packageName = de.manayv.lotto.test
  instrumentationInfo.name = android.support.test.runner.AndroidJUnitRunner

虽然startInstrumentation()返回 true,但不会执行测试。有任何想法吗?

4

1 回答 1

3

我发现了问题。它是 startInstrumentation() 中的第二个空参数。我将代码更改为:

...
Bundle arguments = new Bundle();
arguments.putString("class", "de.manayv.lotto.espresso.BalanceComputationTest");

if (!startInstrumentation(componentName, null, arguments)) {
    Toast.makeText(this, "Cannot run instrumentation for " + packageName,
                   Toast.LENGTH_SHORT).show();
}

要执行 (Java) 包中包含的所有测试,请改用:

arguments.putString("package", "de.manayv.lotto.espresso");
于 2015-06-12T08:02:40.210 回答