Android JVM unit tests showing stdout and stderr via gradle

#android #gradle #jvm #testing #tests #unit

 

Was debugging some test failures today, and was finding it hard to debug because upon failure only a couple lines of stdout and stderr were included in the test report.

Instead wanted to trace through the full log, however, when running the tests via command line with gradle (as our CI does), it was not outputting anything to command line.

Found this approach: https://itecnote.com/tecnote/gradle-how-to-get-output-from-test-stderr-stdout-into-console/ - however its more oriented towards a jvm build, not an android build. After some further digging found a couple other docs: https://developer.android.com/studio/test/advanced-test-setup https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html

And put it together to find that this setup works:

android {
  testOptions {
	  unitTests {
		  all {
			  testLogging {
				  outputs.upToDateWhen {false}
          showStandardStreams = true
				}
			}
		}
	}
}

Hope this helps someone!


Comments (0)


Leave a Comment

Log in to leave a comment.

Most Recent Post

Building a Better GitHub Stats Card

I've had a GitHub profile stats card for a while now, but I was never fully happy with it. The existing tools each had trade-offs that bugged me, so I ended up building my own by combining the best parts of three different projects. Here's how it went. The Problem There are a few popular projects fo...