Android测试用例无法在调试模式下工作

时间:2016-08-19 08:55:54

标签: android android-studio android-testing android-instrumentation

我无法调试android Instrumentation测试用例(使用espresso& UiAutomator)

但早期的测试用例调试工作正常,但最近的更新它不再起作用了。它总是在实例化单元测试时受到攻击 enter image description here

我可以在命令窗口看到它正在尝试启动PACKAGE_NAME **。test **

 adb shell am instrument -w -r   -e debug true -e class PACKAGE_NAME.LanguageScreenTest#testSelectImportant PACKAGE_NAME**.test**/android.support.test.runner.AndroidJUnitRunner

3 个答案:

答案 0 :(得分:0)

如果我使用AndroidOrchestrator,对我来说也是一样。如果您确实不需要使用它运行测试,或者至少在想要调试时,请关闭它。

(已经很长时间了,但对于其他后来可能会遇到此问题的人而言)

答案 1 :(得分:0)

正如@PhạmLam所说,关闭Android Test Orchestrator对我有用。

要“关闭”,我在调试时仅将execution 'ANDROIDX_TEST_ORCHESTRATOR'中的build.gradle行注释掉:

...
android {
  defaultConfig {
   ...
   testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
   testInstrumentationRunnerArguments clearPackageData: 'true'
 }

  testOptions {
    // Comment out below line
    // execution 'ANDROIDX_TEST_ORCHESTRATOR'
  }
}
...

答案 2 :(得分:-1)

问题在于某些配置文件没有在git中跟踪(因此现在无法弄清楚,有空闲时间会这样做)

  

adb shell am instrument -w -r -e debug true -e class PACKAGE_NAME.LanguageScreenTest#testSelectImportant PACKAGE_NAME **。test ** / android.support.test .runner.AndroidJUnitRunner

当debug参数为true时,测试用例在调试模式下不起作用,它将在上面的状态

上进行

当此参数为false时,它可以正常工作

要解决这个问题,我必须使用相同存储库的另一个克隆(我也尝试在相同的工作空间中删除.idea和.gradle,这对我没用)