I would like to see test results ( system.out/err, log messages from components being tested ) as they run in the same console I run:
gradle test
And not wait until tests are done to look at the test reports ( that are only generated when tests are completed, so I can't "tail -f" anything while tests are running )
My favourite minimalistic version based on Shubham Chaudhary answer.
Put this in
build.gradle
file:In Gradle using Android plugin:
Then the output will be:
You can add a Groovy closure inside your build.gradle file that does the logging for you:
On your console it then reads like this:
Since version 1.1 Gradle supports much more options to log test output. With those options at hand you can achieve a similar output with the following configuration:
As stefanglase answered:
adding the following code to your
build.gradle
(since version 1.1) works fine for output on passed, skipped and failed tests.What I want to say additionally (I found out this is a problem for starters) is that the
gradle test
command executes the test only one time per change.So if you are running it the second time there will be no output on test results. You can also see this in the building output: gradle then says UP-TO-DATE on tests. So its not executed a n-th time.
Smart gradle!
If you want to force the test cases to run, use
gradle cleanTest test
.This is slightly off topic but I hope it will help some newbies.
edit
As sparc_spread stated in the comments:
If you want to force gradle to always run fresh tests (which might not always be a good idea) you can add
outputs.upToDateWhen {false}
totestLogging { [...] }
. Continue reading here.Peace.
You could run Gradle with INFO logging level on the command line. It'll show you the result of each test while they are running. Downside is that you will get far more output for other tasks also.
Following on from Benjamin Muschko's answer (19 March 2011), you can use the
-i
flag along with grep, to filter out 1000s of unwanted lines. Examples:Strong filter - Only display each unit test name and result, and the overall build status. Setup errors or exceptions are not displayed.
Soft filter - Display each unit test name and result, as well as setup errors/exceptions. But it will also include some irrelevant info:
Soft filter, Alternative syntax: (search tokens are split into individual strings)
Explanation of how it works: The output of the first command,
./gradlew test -i
, is piped to a second commandgrep
, which will filter out many unwanted lines based on a regular expression."-E"
enables the regular expression mode, and"|"
means "or". A unit test name and result is allowed to display using" > "
, and the overall status is allowed with"BUILD"
. In the soft filter, the"-v"
flag means "not containing" and"^"
means "start of line". So it strips out all lines that start with "Executing " or start with "Creating ", etc.Example for Android instrumentation unit tests, with gradle 5.1:
Example for Jacoco unit test coverage, with gradle 4.10: