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

Searching the Parts of the Internet Google Doesn't: Five Years of darksearch.xyz

There's a whole slice of the internet that's public but almost impossible to search. Content on IPFS is addressed by what it is (a content hash, the CID) rather than where it is, so there's no domain to crawl, no robots.txt, and no single server to point a search engine at. If you don't already have...