如果过滤未在子项目中返回任何测试,请不要使测试失败

时间:2019-02-13 16:10:17

标签: android gradle junit4 android-instrumentation android-junit

我的connectedDebugAndroidTest失败

  

com.android.builder.testing.ConnectedDevice>找不到测试。[SM-A310F-7.0]失败

     

未找到测试。这通常意味着您的测试类的格式不符合测试跑步者期望的形式(例如,不要从TestCase继承或缺少@Test批注)。

这里的问题是我

  1. 在具有两个子项目:lib:mobile
  2. 的父项目上执行任务
  3. 使用过滤器(annotation)运行检测测试。

当我在父项目上运行时,子项目将逐个进行测试。过滤器的确找到了要在:lib中运行的测试,但是在:mobile中没有满足过滤器的测试。对我来说这完全可以,但是测试因而CI失败了。

如果没有找到测试,我如何指示测试不失败(尤其是在找到测试的情况下,但不是在每个子项目中都如此)

我当前的gradle呼叫是这样的:

gradlew.bat --continue connectedDebugAndroidTest
-P android.testInstrumentationRunnerArguments.annotation=android.support.test.filters.FlakyTest

实际上,我使用的是自定义注释,但它的用途与@FlakyTest相同,因此我仅通过一个测试就排除了我的自定义注释的问题。

从同一仪器记录中摘录的相关摘录为:

处理第一个子项目的部分:

I/RemoteAndroidTest: Running am instrument -w -r   -e annotation android.support.test.filters.FlakyTest com.example.lib.test/android.support.test.runner.AndroidJUnitRunner on SM-A310F - 7.0
V/ddms: execute: running am instrument -w -r   -e annotation android.support.test.filters.FlakyTest com.example.lib.test/android.support.test.runner.AndroidJUnitRunner
V/InstrumentationResultParser: INSTRUMENTATION_STATUS: numtests=1
V/InstrumentationResultParser: INSTRUMENTATION_STATUS: stream=
V/InstrumentationResultParser: com.example.lib.activities.MainActivityTest:
V/InstrumentationResultParser: INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
V/InstrumentationResultParser: INSTRUMENTATION_STATUS: test=testOnCreate
V/InstrumentationResultParser: INSTRUMENTATION_STATUS: class=com.example.lib.activities.MainActivityTest
V/InstrumentationResultParser: INSTRUMENTATION_STATUS: current=1
1 tests on SM-A310F - 7.0
V/InstrumentationResultParser: INSTRUMENTATION_STATUS_CODE: 1
V/InstrumentationResultParser: INSTRUMENTATION_STATUS: numtests=1
V/InstrumentationResultParser: INSTRUMENTATION_STATUS: stream=.
V/InstrumentationResultParser: INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
V/InstrumentationResultParser: INSTRUMENTATION_STATUS: test=testOnCreate
V/InstrumentationResultParser: INSTRUMENTATION_STATUS: class=com.example.lib.activities.MainActivityTest
V/InstrumentationResultParser: INSTRUMENTATION_STATUS: current=1
V/InstrumentationResultParser: INSTRUMENTATION_STATUS_CODE: 0
V/InstrumentationResultParser: INSTRUMENTATION_RESULT: stream=
V/InstrumentationResultParser: 
V/InstrumentationResultParser: Time: 1,362
V/InstrumentationResultParser: 
V/InstrumentationResultParser: OK (1 test)
V/InstrumentationResultParser: 
V/InstrumentationResultParser: INSTRUMENTATION_CODE: -1
V/InstrumentationResultParser: 
I/XmlResultReporter: XML test result file generated at TEST-SM-A310F - 7.0-lib.xml. Total tests 1, passed 1, 
V/ddms: execute 'am instrument -w -r   -e annotation android.support.test.filters.FlakyTest com.example.lib.test/android.support.test.runner.AndroidJUnitRunner' on '31006b2f91c74311' : EOF hit. Read: -1
V/ddms: execute: returning
V/ddms: execute: running pm uninstall com.example.lib.test
V/ddms: execute 'pm uninstall com.example.lib.test' on '31006b2f91c74311' : EOF hit. Read: -1
V/ddms: execute: returning

....

处理第一个子项目的部分:

....
I/RemoteAndroidTest: Running am instrument -w -r   -e annotation android.support.test.filters.FlakyTest com.example.mobile.test/android.support.test.runner.AndroidJUnitRunner on SM-A310F - 7.0
V/ddms: execute: running am instrument -w -r   -e annotation android.support.test.filters.FlakyTest com.example.mobile.test/android.support.test.runner.AndroidJUnitRunner
V/InstrumentationResultParser: INSTRUMENTATION_RESULT: stream=
V/InstrumentationResultParser: 
V/InstrumentationResultParser: Time: 0,001
V/InstrumentationResultParser: 
V/InstrumentationResultParser: OK (0 tests)
V/InstrumentationResultParser: 
V/InstrumentationResultParser: 
V/InstrumentationResultParser: INSTRUMENTATION_CODE: -1
V/InstrumentationResultParser: 
0 tests on SM-A310F - 7.0
I/XmlResultReporter: XML test result file generated at TEST-SM-A310F - 7.0-mobile.xml. Total tests 0, 
V/ddms: execute 'am instrument -w -r   -e annotation android.support.test.filters.FlakyTest com.example.mobile.test/android.support.test.runner.AndroidJUnitRunner' on '31006b2f91c74311' : EOF hit. Read: -1
V/ddms: execute: returning

com.android.builder.testing.ConnectedDevice > No tests found.[SM-A310F - 7.0] FAILED 
No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @Test annotations).
05:00:56 I/XmlResultReporter: XML test result file generated at TEST-SM-A310F - 7.0-mobile.xml. Total tests 1, failure 1, 
05:00:56 V/ddms: execute: running pm uninstall com.example.mobile.test
05:00:58 V/ddms: execute 'pm uninstall com.example.mobile.test' on '31006b2f91c74311' : EOF hit. Read: -1
05:00:58 V/ddms: execute: returning
05:00:58 V/ddms: execute: running pm uninstall com.example.mobile
05:01:00 V/ddms: execute 'pm uninstall com.example.mobile' on '31006b2f91c74311' : EOF hit. Read: -1
05:01:00 V/ddms: execute: returning

> Task :mobile:connectedDebugAndroidTest FAILED

FAILURE: Build failed with an exception.

0 个答案:

没有答案
相关问题