Browse Source

Configure JUL/log4j for JUnit 5 in spring-test

Issue: SPR-14431
pull/1070/merge
Sam Brannen 9 years ago
parent
commit
adfea826cc
  1. 4
      build.gradle
  2. 10
      spring-test/src/test/java/org/springframework/test/context/junit/SpringJUnitJupiterTestSuite.java
  3. 1
      spring-test/src/test/resources/log4j2-test.xml

4
build.gradle

@ -890,6 +890,8 @@ project("spring-test") { @@ -890,6 +890,8 @@ project("spring-test") {
testCompile("org.apache.httpcomponents:httpclient:${httpclientVersion}")
testCompile("javax.cache:cache-api:1.0.0")
testRuntime("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")
// Java Util Logging for JUnit 5.
testRuntime("org.apache.logging.log4j:log4j-jul:${log4jVersion}")
testRuntime("org.ehcache:ehcache:${ehcache3Version}")
testRuntime("org.terracotta:management-model:2.0.0")
}
@ -911,6 +913,8 @@ project("spring-test") { @@ -911,6 +913,8 @@ project("spring-test") {
scanForTestClasses = false
include(['**/*Tests.class', '**/*Test.class', '**/SpringJUnitJupiterTestSuite.class'])
exclude(['**/testng/**/*.*'])
// Java Util Logging for JUnit 5.
// systemProperty('java.util.logging.manager', 'org.apache.logging.log4j.jul.LogManager')
}
task aggregateTestReports(type: TestReport) {

10
spring-test/src/test/java/org/springframework/test/context/junit/SpringJUnitJupiterTestSuite.java

@ -31,6 +31,16 @@ import org.junit.runner.RunWith; @@ -31,6 +31,16 @@ import org.junit.runner.RunWith;
* build. This class is therefore responsible for executing all JUnit
* Jupiter based tests in Spring's official test suite.
*
* <h3>Logging Configuration</h3>
*
* <p>In order for our log4j2 configuration to be used in an IDE, you must
* set the following system property before running any tests &mdash; for
* example, in <em>Run Configurations</em> in Eclipse.
*
* <pre style="code">
* -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager
* </pre>
*
* @author Sam Brannen
* @since 5.0
*/

1
spring-test/src/test/resources/log4j2-test.xml

@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
</File>
</Appenders>
<Loggers>
<Logger name="org.junit.platform" level="info" />
<Logger name="org.springframework.test.context" level="warn" />
<Logger name="org.springframework.test.context.TestContext" level="warn" />
<Logger name="org.springframework.test.context.TestContextManager" level="warn" />

Loading…
Cancel
Save