Gradle:如何在控制台中显示androidTest结果?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (70)

这可以通过以下任务进行设置:

tasks.withType(Test) {
    testLogging {
       // Custom configuration
    }
}

这适用于单元测试,看起来有点像这样:

...
:app:assembleDebugUnitTest
:app:testDebugUnitTest
:app:processDebugResources

com.example.StringsTest > formatValue PASSED
com.example.StringsTest > formatValueWithDecimals FAILED

1 test completed, 1 failed

此外,我还使用以下命令运行集成测试

$ ./gradlew connectedAndroidTest

如何配置仪器测试的测试日志?

提问于
用户回答回答于

简单的版本只是使用:

./gradlew connectedAndTestTest --info

在终端/控制台窗口中记录它需要一点点时间,但它显示了一切很好,颜色和格式:

…ShowsIntroduction[SM-G950F - 7.0] SUCCESS 
…BackButtonReturnsToOnboardingScreen[SM-G950F - 7.0] SKIPPED
用户回答回答于

我使用以下脚本adb logcat在后台启动,在TestRunner测试执行时记录事件,然后终止logcat进程:

adb logcat *:S TestRunner:V & LOGCAT_PID=$! ; \
./gradlew :app:cAT ; \
if [ -n "$LOGCAT_PID" ] ; then kill $LOGCAT_PID; fi

这产生了这样的事情:

[1] 90439
--------- beginning of system
--------- beginning of main
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
...
:app:packageDebugAndroidTest UP-TO-DATE
:app:assembleDebugAndroidTest UP-TO-DATE
> Building 96% > :app:connectedDebugAndroidTest06-13 09:25:04.259  5460  5474 I TestRunner: run started: 23 tests
06-13 09:25:04.267  5460  5474 I TestRunner: started: testHomeClick(io.github.hidroh.tldroid.CommandActivityTest)
06-13 09:25:06.899  5460  5474 I TestRunner: finished: testHomeClick(io.github.hidroh.tldroid.CommandActivityTest)
06-13 09:25:06.903  5460  5474 I TestRunner: started: testRenderNoContent(io.github.hidroh.tldroid.CommandActivityTest)
06-13 09:25:08.128  5460  5474 I TestRunner: finished: testRenderNoContent(io.github.hidroh.tldroid.CommandActivityTest)
06-13 09:25:08.130  5460  5474 I TestRunner: started: testStateRestoration(io.github.hidroh.tldroid.CommandActivityTest)
06-13 09:25:09.547  5460  5474 I TestRunner: finished: testStateRestoration(io.github.hidroh.tldroid.CommandActivityTest)
...
06-13 09:25:35.283  5460  5474 I TestRunner: run finished: 23 tests, 0 failed, 0 ignored
:app:connectedDebugAndroidTest
:app:createDebugAndroidTestCoverageReport
:app:connectedAndroidTest

BUILD SUCCESSFUL

Total time: 1 mins 7.485 secs
[1]+  Terminated: 15          adb logcat *:S TestRunner:V

扫码关注云+社区