As explained in other threads Gradle can be configured to log test results into the console:
Basically, this can be setup through the following task:
tasks.withType(Test) {
testLogging {
// Custom configuration
}
}
This works fine for unit tests and looks somewhat like this:
...
:app:assembleDebugUnitTest
:app:testDebugUnitTest
:app:processDebugResources
com.example.StringsTest > formatValue PASSED
com.example.StringsTest > formatValueWithDecimals FAILED
1 test completed, 1 failed
Besides, unit tests I also run integration test using the following command:
$ ./gradlew connectedAndroidTest
When I look at the output in the console I am missing the individual test results as being written for unit tests. How can I configure test logging for instrumentation tests?
Connected tests log output and events to logcat
, as it runs on a device/emulator. Test events are logged under TestRunner
tag.
I use the following script to start adb logcat
in the background, which logs TestRunner
events as tests are being executed, and kill the logcat
process afterwards.
adb logcat *:S TestRunner:V -T 1 & LOGCAT_PID=$! ; \
./gradlew :app:cAT ; \
if [ -n "$LOGCAT_PID" ] ; then kill $LOGCAT_PID; fi
which produces something like this:
[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
You can of course tweak logcat
command to use a logger of your choice, e.g. a color logger, or change logcat filterspec
to show more events.
The easy version is just to use:
./gradlew connectedAndroidTest --info
it take a littlebit to log it in the terminal/console window, but it's showing everything nice, colored and formatted
like …
…ShowsIntroduction[SM-G950F - 7.0] SUCCESS
…BackButtonReturnsToOnboardingScreen[SM-G950F - 7.0] SKIPPED
good luck && have fun
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With