Tricky Android

Android tips, tricks and everything I found interesting

Gradle tip #4: Log unit test execution events into console

Today's tip will be really short (but hopefully useful).

I personally run Android unit tests manually from command line really often (./gradlew test) - just a habit I believe. However, by default, gradle just silently runs unit test suite w/o communicating progress. Essentially it just fails if some of the unit tests fails:

:app:processDebugJavaRes UP-TO-DATE
:app:processDebugUnitTestJavaRes UP-TO-DATE
:app:mockableAndroidJar UP-TO-DATE

Total time: 4.725 secs

What I found useful for myself - is to make gradle indicate what test is being executed. Something like this:

com.trickyandroid.testproj.ExampleUnitTest > exampleTest1 PASSED
com.trickyandroid.testproj.ExampleUnitTest > exampleTest2 PASSED
com.trickyandroid.testproj.ExampleUnitTest > exampleTest3 PASSED

Total time: 4.107 secs

What you need to do - is just add the following to your build.gradle script (top level, not under android closure):

tasks.matching {it instanceof Test}.all { = ["failed", "passed", "skipped"]

What it does - is configures all JUnit (or TestNG) test tasks to write message to console whenever "test failed" / "test passed" / "test skipped" events occur.

More about test tasks configuration you can read in official Gradle documentation

comments powered by Disqus