我正在使用adb测试命令一次在多个设备上运行测试。我的伪外壳脚本如下所示:Android咖啡控制台日志Build.Serial onFail
for each device
adb -s ${device} shell am instrument -w -e ${classOrPkg} ${androidTestPackage}${test_name} ${main_package}.${flavor}.test/android.support.test.runner.AndroidJUnitRunner &
问题是当测试失败时,我没有关于发生故障的设备的信息。我可以使用LogCat,但它需要为每个设备查找logcat。而且,System.out.println()不起作用。
我想,现在一个可能的解决方案是通过扩展TestWatcher类并覆盖这样的失败()方法,
public class TestWatcherRule extends TestWatcher {
@Override
protected void failed(Throwable e, Description description) {
Description d = Description.createTestDescription(e.getClass(), "<<<< Failed on Device: " + Build.SERIAL);
super.failed(e, d);
}
}
实现:
@Rule
public TestWatcher testWatcher = new TestWatcherRule();
assertThat("My message", true, is(false));
我不能让设备序列尚未在终端上。
我的预期产出将是这样的:
com.myapp.mobile.tests.BenefitCardDBTest:
Error in addDeleteCard(com.myapp.mobile.tests.BenefitCardDBTest):
**<<<< Failed on Device: HTC10xwrtxe**
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: com.myapp.mobile.qa:id/drawer_layout
谢谢你的答复。我忘记提及,我知道通过使用gradle任务以这种方式运行测试。唯一的问题是测试不能立即运行,即gradle builds,安装apks,运行测试并卸载apk。我喜欢adb命令,因为它会立即运行测试。你知道一种跳过构建部分的方法,只需使用gradle connectedCheck命令运行测试? –
我不太了解Gradle,但是尝试使用找到哪些命令是“connectedAndroidTest”或“connectedCheck”。也许'./gradlew test'会跳过建设 – piotrek1543