Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set test.testLogging.showStandardStreams to true from the command line?

Tags:

gradle

It is convenient to debug some of external libraries and even internal code while writing unit tests by reviewing the logging on stdout.

While I can add test.testLogging.showStandardStreams = true to the build.graddle file, I'd rather do something less permanent, such as setting this flag from the command line execution of gradle.

I've tried several approaches, none seem to work:

gradle test -Dtest.testLogging.showStandardStreams=true
gradle test -Ptest.testLogging.showStandardStreams=true

And other variations of those options by changing the property string. Nothing seems to do the trick.

How do I set test.testLogging.showStandardStreams=true from the command line?

like image 622
Bill Door Avatar asked Jan 29 '14 21:01

Bill Door


People also ask

How do I run a specific test in gradle?

You can do gradle -Dtest. single=ClassUnderTestTest test if you want to test single class or use regexp like gradle -Dtest. single=ClassName*Test test you can find more examples of filtering classes for tests under this link.

How do I create a test report in gradle?

How to generate a Test Report. Gradle generates a Test Report automatically when it runs the entire Test Suite. To do the same, run ./gradlew test (or gradlew. bat test from Windows), or run the test Gradle task from your IDE.

What is useJUnitPlatform?

useJUnitPlatform() Specifies that JUnit Platform should be used to discover and execute the tests.


3 Answers

There is no built-in way to set build model properties from the command line. You'll have to make the build script query a system or project property that gets passed in via -D or -P, respectively.

like image 168
Peter Niederwieser Avatar answered Oct 04 '22 06:10

Peter Niederwieser


Just use environment variables:

test {
    testLogging.showStandardStreams = (System.getenv('PRINTF_DEBUG') != null)
}

Now run your test case like this:

PRINTF_DEBUG=1 ./gradlew test --tests=com.yourspace.yourtest

This will run enable console output and just run one single test case. You often not want to enable console output for the entire test suite because of the noise generated.

like image 38
Guido Flohr Avatar answered Oct 04 '22 06:10

Guido Flohr


You can override it like this

gradle -Doverride.test.testLogging.info.showStandardStreams=true test

or you can add this to your gradle.properties either in the project or in ~/.gradle/gradle.properties

systemProp.override.test.testLogging.info.showStandardStreams=true
like image 21
conorgriffin Avatar answered Oct 04 '22 06:10

conorgriffin