使用gradle运行Espresso测试用例并检查HTML测试报告时,我只能看到PASS和FAIL测试用例,而不能看到IGNORED。 在进行一些故障排除时,我强制使用Assume并使其通过一个IGNORED测试用例:
@Test
public void test_1() {
Assume.assumeTrue("No WiFi connection. Set test to Ignored",false);
}
@Test
public void test_2() {
Assert.assertTrue(true);
}
我运行带有--info标志的gradlew app:connectedDebugAndroidTest的输出是:
在emulator25(AVD)-7.1.1上开始2个测试
com.myapp.androidTest> test_1 [emulator25(AVD)-7.1.1]跳过 org.junit.AssumptionViolatedException:没有WiFi连接。将测试设置为“已忽略” 在org.junit.Assume.assumeTrue(Assume.java:59)
com.myapp.androidTest> test_1 [emulator25(AVD)-7.1.1]成功
com.myapp.androidTest> test_2 [emulator25(AVD)-7.1.1]成功
由于某种原因,显然test_1从SKIPPED转到SUCCESS,因此在HTML测试报告中,test_1和test_2显示为PASSED。
但是,查看XML测试结果,有被忽略的测试:
<testsuite name="com.myapp.androidTest" tests="2" failures="0" errors="0" skipped="0" time="5.055" timestamp="2018-08-23T14:30:50" hostname="localhost"> <properties> <property name="device" value="emulator25(AVD) - 7.1.1"/> <property name="flavor" value="GLOBAL"/>
<property name="project" value="app"/> </properties> <testcase name="test_1" classname="com.myapp.androidTest" time="2.99"> <skipped> org.junit.AssumptionViolatedException: No WiFi connection. Set test to Ignored at org.junit.Assume.assumeTrue(Assume.java:59) at com.myapp.androidTest.test_1(Iqiyi_DefaultSettings_VideoEvents_WIFI.java:124) at java.lang.reflect.Method.invoke(Native Method) at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at android.support.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:80) at android.support.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:61) at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:527) at android.support.test.rule.GrantPermissionRule$RequestPermissionStatement.evaluate(GrantPermissionRule.java:129) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at android.support.test.runner.AndroidJUnit4.run(AndroidJUnit4.java:101) at org.junit.runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:27) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at org.junit.runner.JUnitCore.run(JUnitCore.java:115) at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:56) at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:384) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1932)
</skipped> </testcase> <testcase name="test_2" classname="com.myapp.androidTest" time="1.105"/> </testsuite>
知道发生了什么吗?
使用Gradle 4.4.1
PS。对于单元测试没有问题,并且显示了被忽略的测试