將測試日誌輸出和事件連接到logcat
,因爲它在設備/仿真器上運行。測試事件記錄在TestRunner
標籤下。
我使用以下腳本在後臺啓動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
當然你也可以TWEAK的logcat命令來使用你選擇,例如一個記錄器彩色記錄器,或更改logcat filterspec以顯示更多事件。
這次JJD的運氣怎麼樣? –
還沒有。說實話,我不得不推遲這些測試一段時間。一旦事情「恢復正常」,我會盡快把它拿起來。你試過hidro的方法嗎? – JJD
不,我只是想要一個基於Gradle的方法。我希望像'tasks.withTest'一樣。 –