While testing with Gradle, I'd like to show standard streams on the console only when I run a specific subset of tests with the --tests
option.
Let me elaborate. On build.gradle
I have
test {
testLogging {
//showStandardStreams = true
}
}
Usually, when I run my whole test suite, I don't like to have console output from the tests. But when I'm working on a specific test, it's very useful to have console output, so I go ahead and uncomment that line before executing that test with gradle test --tests *name
.
I'd like to know if there's an automated way to do that.
EDIT: Let my clarify. I'd like to have console output when I run gradle test --tests *name
, but not when I run gradle test
.
To get console output on some runs for all tests, you could supply an additional parameter (-Poutput) on command-line:
gradle test --tests *name -Poutput
test {
onOutput { descriptor, event ->
if (project.hasProperty('output')) {
logger.lifecycle(event.message)
}
}
}
To get console output on a specific test only:
test {
onOutput { descriptor, event ->
if (descriptor.name=='YOUR_TEST_METHOD_NAME' &&
descriptor.className=='YOUR_PACKAGE_QUALIFIED_CLASS_NAME') {
logger.lifecycle(event.message)
}
}
}
See TestDescriptor and Test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With