I have set the default test lifecycle to per_class
for a project using JUnit5. This is done in the junit-platform.properties
file. However, since applying this configuration, my test runs are now preceded by a lot of logging output:
Dec 06, 2018 8:15:22 PM org.junit.platform.launcher.core.LauncherConfigurationParameters fromClasspathResource
INFO: Loading JUnit Platform configuration parameters from classpath resource [file:/Users/amb85/Projects/kotlin/katas/out/test/resources/junit-platform.properties].
Dec 06, 2018 8:15:22 PM org.junit.jupiter.engine.descriptor.TestInstanceLifecycleUtils getDefaultTestInstanceLifecycle
INFO: Using default test instance lifecycle mode 'PER_CLASS' set via the 'junit.jupiter.testinstance.lifecycle.default' configuration parameter.
I don't want to see these log messages. How do I disable them or set the log level higher?
JUnit Jupiter: Provides an annotation-based API to write JUnit 5 unit tests, along with a test engine that lets you run them. JUnit Vintage: Offers a test engine to run JUnit 3 and JUnit 4 tests, thereby ensuring backward compatibility (with earlier versions of the JUnit framework).
Running tests with IntelliJ IDEA Vintage engine discovers and runs the JUnit 4 tests. Jupiter runs its own discovery and execution phases where it discovers and executes JUnit 5 tests only. So not that you can only run JUnit 4 and JUnit 5 tests in the same project, you can also do that in the same test class.
To disable a test in JUnit 5, you will need to use @Disabled annotation.
Found an answer in: https://github.com/junit-team/junit5/issues/1774#issuecomment-463662553
Summarizing: Set 'java.util.logging.config.file' system property pointing to a logging.properties file that reduces the log level.
tasks.withType(Test).configureEach {
useJUnitPlatform()
systemProperty 'java.util.logging.config.file', "${project.buildDir}/resources/test/logging-test.properties"
testLogging {
showStandardStreams = true
}
}
logging-test.properties:
handlers=java.util.logging.ConsoleHandler
.level=INFO
org.junit.platform.launcher.core.LauncherConfigurationParameters.level=WARNING
org.junit.jupiter.engine.config.EnumConfigurationParameterConverter.level=WARNING
I'm also having the same issue. A possible solution may be to intercept the default JUnit5 logger (java.util.logging.LogManager) and discard that INFO log. I have not yet implemented it, but you are not alone with this.
Here's some links from my research:
https://junit.org/junit5/docs/current/user-guide/#writing-tests-test-instance-lifecycle-changing-default
https://junit.org/junit5/docs/current/user-guide/#writing-tests-test-interfaces-and-default-methods
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