正如其他线程中所解释的,Gradle 可以配置为将测试结果记录到控制台中:
- Gradle Android: How to Display test results without using --info
- Gradle: How to Display Test Results in the Console in Real Time?
- Output unit testing results on console using spock junit testing and gradle build system
基本上,这可以通过以下任务进行设置:
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
当我查看控制台中的输出时,我缺少单个测试结果,因为它是为单元测试编写的。如何为检测测试配置测试日志记录?
最佳答案
已连接的测试将输出和事件记录到 logcat
,因为它在设备/模拟器上运行。测试事件记录在 TestRunner
标签下。
我使用以下脚本在后台启动 adb logcat
,在执行测试时记录 TestRunner
事件,并杀死 logcat
事后处理。
adb logcat *:S TestRunner:V -T 1 & 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
您当然可以调整 logcat
命令以使用您选择的记录器,例如颜色记录器,或更改 logcat filterspec
以显示更多事件。
关于android - Gradle:如何在控制台中显示 androidTest 结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36914675/