Colored and folded output for Gradle tests in Travis

When running Gradle tests on Travis CI, the terminal is usually set to dumb mode, so you get very plain looking output. However, Travis does allow for colors in their logs.

Gradle script plugin which formats test output in a slightly colorful way (made for Travis CI but works in terminal)

This Gradle script plugin formats the Gradle test output in a slightly colorful way (made for Travis CI but works in terminal). It also adds a summary at the end.



Add the ColoredOutput.gradle script to your project, for example at buildtools/ColoredOutput.gradle

At the top of your build.gradle, reference it.

apply from: 'buildtools/ColoredOutput.gradle'

If you want Travis folding, you can enable it like so:

apply from: 'buildtools/ColoredOutput.gradle'
project.ext.set("TRAVIS_FOLDING", true)

If you run your build on Travis you should now see colored output.


See Travis CI Example

Additionally you will see colored output in the terminal.


How it works

This script makes use of Gradle’s TestListener class which provides methods that run before and after tests and test suites are run.

The script uses the results passed in afterTest to render for success, for failure or ಠ_ಠ for skipped tests.

At the end, the afterSuite method renders a summary using various ANSI colors which Travis recognizes and renders.