I am trying to log the JUnit ClassOrderer random seed using Logback, Spring Boot and Gradle. I found How can I make my JUnit tests run in random order? as related to my problem, but it uses the JUL framework for logging rather than Logback.
I am expecting the following output from ./gradlew clean test
, but it does not appear with my configuration below:
Gradle Test Executor 2 STANDARD_ERROR
Apr 06, 2024 3:59:00 PM org.junit.jupiter.api.ClassOrderer$Random <clinit>
CONFIG: ClassOrderer.Random default seed: 5480048958461
Apr 06, 2024 3:59:00 PM org.junit.jupiter.api.MethodOrderer$Random <clinit>
CONFIG: MethodOrderer.Random default seed: 5480082278753
Can someone spot the problem?
build.gradle file
plugins {
id("org.springframework.boot") version "3.2.4"
id("io.spring.dependency-management") version "1.1.4"
kotlin("jvm") version "1.9.23"
kotlin("plugin.spring") version "1.9.23"
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.testcontainers:junit-jupiter")
}
tasks.withType<Test> {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed", "standardOut", "standardError")
}
}
src/test/resources/logback-spring.xml file
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<root level="DEBUG">
<appender-ref ref="CONSOLE" />
</root>
<!-- According to https://jira.qos.ch/browse/LOGBACK-1612 DEBUG should include JUL CONFIG -->
<!-- Name property based on https://github.com/junit-team/junit5/blob/main/junit-jupiter-api/src/main/java/org/junit/jupiter/api/MethodOrderer.java -->
<logger name="org.junit.jupiter.api.ClassOrderer$Random" level="DEBUG"/>
<logger name="org.junit.jupiter.api.MethodOrderer$Random" level="DEBUG"/>
</configuration>
src/test/resources/junit-platform.properties file
junit.jupiter.testmethod.order.default = org.junit.jupiter.api.MethodOrderer$Random
junit.jupiter.testclass.order.default = org.junit.jupiter.api.ClassOrderer$Random
I also tried setting "logging.config" and "logback.configurationFile" in systemProperties
via Gradle without success:
tasks.withType<Test> {
systemProperties(
"logging.config" to file("src/test/resources/logback-spring.xml")
"logback.configurationFile" to file("src/test/resources/logback-spring.xml")
)
// To print the JUnit logs in console
testLogging {
events("passed", "skipped", "failed", "standardOut", "standardError")
}
}