Android 报告 "Error=Unable to find instrumentation info for: ComponentInfo {}"

标签 android automation android-espresso bitrise

在 stackoverflow(例如 Error=Unable to find instrumentation info for: ComponentInfo{ })和其他网站上有很多关于这个问题的主题/问题,但让我的问题与其他问题不同的是我正在研究自动化。因此,让我为您提供更多详细信息。

我在本地机器上测试时没有问题(我的意思是我的笔记本电脑)。我可以运行 Espresso 测试并且所有测试都通过了。

现在,我想在 CI(在我的例子中是 Bitrise)上运行这些测试。我创建并运行模拟器。我确认那里没有问题。我有以下脚本:

...
# Check which instrumentation packages have been installed on your device, https://stackoverflow.com/a/23394559/513413
echo ""
echo "Check which instrumentation packages have been installed..."
adb shell pm list instrumentation

# Running tests
echo ""
echo "running test..."
adb shell am instrument -w -r   -e debug false -e class my.package.name.MyActivityTest my.package.name.test/android.support.test.runner.AndroidJUnitRunner

这是 CI 的输出:

Check which instrumentation packages have been installed...
instrumentation:com.android.emulator.smoketests/android.support.test.runner.AndroidJUnitRunner (target=com.android.emulator.smoketests)
instrumentation:com.android.smoketest.tests/com.android.smoketest.SmokeTestRunner (target=com.android.smoketest)
instrumentation:com.example.android.apis/.app.LocalSampleInstrumentation (target=com.example.android.apis)
running test...
INSTRUMENTATION_STATUS: id=ActivityManagerService
INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{my.package.name.test/android.support.test.runner.AndroidJUnitRunner}
INSTRUMENTATION_STATUS_CODE: -1
android.util.AndroidException: INSTRUMENTATION_FAILED: my.package.name.test/android.support.test.runner.AndroidJUnitRunner
    at com.android.commands.am.Am.runInstrument(Am.java:1093)
    at com.android.commands.am.Am.onRun(Am.java:371)
    at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
    at com.android.commands.am.Am.main(Am.java:100)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:251)

我在 app.gradle 文件的 defaultConfig 中有以下代码行:

testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'

如您在以下链接中所见,我的 EditConfiguration 下有 android.support.test.runner.AndroidJUnitRunner

enter image description here

我想我的测试失败了,因为我的 CI 模拟器中没有这个命令。所以我的问题是如何通过命令行添加它?这可能吗?

更新

这是我的完整脚本。

#!/bin/bash

# List of devices attached
adb devices

# List all *.apk files inside /bitrise/deploy path
echo "List of all *.apk files in $BITRISE_DEPLOY_DIR"
cd $BITRISE_DEPLOY_DIR && ls

# Push and Install main apk file
echo ""
echo "Pushing main apk at $BITRISE_APK_PATH to /data/local/tmp/my.package.name and install it..."
adb push $BITRISE_APK_PATH /data/local/tmp/my.package.name
adb shell pm install -r "/data/local/tmp/my.package.name"

# Push and Install Test Unaligned apk file
echo ""
echo "Pushing test unaligned apk at $BITRISE_DEPLOY_DIR/my-app-debug-unaligned.apk to /data/local/tmp/my.package.name.test and install it..."
adb push $BITRISE_DEPLOY_DIR/my-app-debug-unaligned.apk /data/local/tmp/my.package.name.test
adb shell pm install -r "/data/local/tmp/my.package.name.test"

# Check which instrumentation packages have been installed on your device, https://stackoverflow.com/a/23394559/513413
echo ""
echo "Check which instrumentation packages have been installed..."
adb shell pm list instrumentation

# Running tests
echo ""
echo "switch directory to $BITRISE_SOURCE_DIR"
cd $BITRISE_SOURCE_DIR
echo "running test..."
adb shell am instrument -w -r -e debug false -e class my.package.name.path.MinHappyPathTest my.package.name.path/android.support.test.runner.AndroidJUnitRunner

最佳答案

在运行“adb shell am instrument”之前,您必须安装(adb install)和应用 APK 以及测试 APK(这是​​不同的 APK)。

关于Android 报告 "Error=Unable to find instrumentation info for: ComponentInfo {}",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36753486/

相关文章:

Android 设备 API 级别与版本不匹配

java - Selenium:当某些 xpath 没有元素时如何编写 if 条件

android - 在测试用例 Espresso 之前清除数据库

javascript - GCM 和服务器端相关问题

android - 无法在我的 Android 应用程序中查看 Google map

python - 我需要将一个文件夹中的所有 .xlsx 文件保存到另一个文件夹中

javascript - 如何自动化/脚本化注册等流程

android - Android float 操作按钮菜单项上的 Espresso UI 测试

android - 在测试期间显示触摸

java - 错误 ':app:packageAllDebugClassesForMultiDex'。 > java.util.zip.ZipException : duplicate entry: com/squareup/picasso/RequestWeakReference