Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JUnit5 properties file causes unwanted logging during test runs

Tags:

junit5

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?

like image 294
amb85 Avatar asked Dec 06 '18 20:12

amb85


People also ask

Which of the following components is used to provide backward compatibility in junit5?

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).

Is it possible to use JUnit 4 and JUnit 5 tests in the same test project or suite )?

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.

Which of the following annotations will prevent a JUnit 5 test from being executed?

To disable a test in JUnit 5, you will need to use @Disabled annotation.


2 Answers

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
like image 91
LaFayette Avatar answered Jan 03 '23 18:01

LaFayette


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

like image 40
Kaylen Travis Pillay Avatar answered Jan 03 '23 18:01

Kaylen Travis Pillay