Skip to content

Commit aed3bda

Browse files
authored
Document Maven Surefire/Failsafe version alignment (#3125)
Resolves #3093.
1 parent 6bc885a commit aed3bda

File tree

5 files changed

+196
-10
lines changed

5 files changed

+196
-10
lines changed

documentation/src/docs/asciidoc/user-guide/running-tests.adoc

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,22 +244,38 @@ additional dependency to the runtime classpath.
244244
[[running-tests-build-maven]]
245245
==== Maven
246246

247-
[WARNING]
248-
.The JUnit Platform Maven Surefire Provider has been discontinued
249-
====
250-
The `junit-platform-surefire-provider`, which was originally developed by the JUnit team,
251-
was deprecated in JUnit Platform 1.3 and discontinued in 1.4. Please use Maven Surefire's
252-
native support instead.
253-
====
254-
255247
Starting with https://issues.apache.org/jira/browse/SUREFIRE-1330[version 2.22.0], Maven
256248
Surefire and Maven Failsafe provide
257249
https://maven.apache.org/surefire/maven-surefire-plugin/examples/junit-platform.html[native support]
258250
for executing tests on the JUnit Platform. The `pom.xml` file in the
259251
`{junit5-jupiter-starter-maven}` project demonstrates how to use the Maven Surefire plugin
260252
and can serve as a starting point for configuring your Maven build.
261253

262-
NOTE: See <<running-tests-build-spring-boot>> for details on how to override the version
254+
[WARNING]
255+
.Use Maven Surefire/Failsafe 3.0.0-M4 or later to avoid interoperability issues
256+
====
257+
Maven Surefire/Failsafe 3.0.0-M4
258+
https://issues.apache.org/jira/browse/SUREFIRE-1585[introduced support] for aligning the
259+
version of the JUnit Platform Launcher it uses with the JUnit Platform version found on
260+
the test runtime classpath. Therefore, it is recommended to use version 3.0.0-M4 or later
261+
to avoid interoperability issues.
262+
263+
Alternatively, you can add a test dependency on the matching version of the JUnit Platform
264+
Launcher to your Maven build as follows.
265+
266+
[source,xml]
267+
[subs=attributes+]
268+
----
269+
<dependency>
270+
<groupId>org.junit.platform</groupId>
271+
<artifactId>junit-platform-launcher</artifactId>
272+
<version>{platform-version}</version>
273+
<scope>test</scope>
274+
</dependency>
275+
----
276+
====
277+
278+
TIP: See <<running-tests-build-spring-boot>> for details on how to override the version
263279
of JUnit used in your Spring Boot application.
264280

265281
[[running-tests-build-maven-engines-configure]]

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ktlint = "0.43.0"
1313
log4j = "2.19.0"
1414
opentest4j = "1.2.0"
1515
openTestReporting = "0.1.0-M1"
16-
surefire = "2.22.2"
16+
surefire = "3.0.0-M7"
1717
xmlunit = "2.9.0"
1818

1919
[libraries]
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example</groupId>
7+
<artifactId>maven-surefire-compatibility</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
<maven.compiler.source>1.8</maven.compiler.source>
13+
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
14+
<junit.jupiter.version>${env.JUNIT_JUPITER_VERSION}</junit.jupiter.version>
15+
<junit.platform.version>${env.JUNIT_PLATFORM_VERSION}</junit.platform.version>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.junit.jupiter</groupId>
21+
<artifactId>junit-jupiter</artifactId>
22+
<version>${junit.jupiter.version}</version>
23+
<scope>test</scope>
24+
</dependency>
25+
</dependencies>
26+
27+
<build>
28+
<plugins>
29+
<plugin>
30+
<artifactId>maven-compiler-plugin</artifactId>
31+
<version>3.8.1</version>
32+
</plugin>
33+
<plugin>
34+
<artifactId>maven-surefire-plugin</artifactId>
35+
<version>${surefire.version}</version>
36+
<configuration>
37+
<properties>
38+
<configurationParameters>
39+
junit.platform.listeners.uid.tracking.enabled = true
40+
</configurationParameters>
41+
</properties>
42+
</configuration>
43+
</plugin>
44+
</plugins>
45+
</build>
46+
47+
<repositories>
48+
<repository>
49+
<id>local-temp</id>
50+
<url>file://${maven.repo}</url>
51+
<snapshots>
52+
<enabled>true</enabled>
53+
</snapshots>
54+
<releases>
55+
<enabled>true</enabled>
56+
</releases>
57+
</repository>
58+
</repositories>
59+
60+
<profiles>
61+
<profile>
62+
<id>manual-platform-dependency</id>
63+
<dependencies>
64+
<dependency>
65+
<groupId>org.junit.platform</groupId>
66+
<artifactId>junit-platform-launcher</artifactId>
67+
<version>${junit.platform.version}</version>
68+
<scope>test</scope>
69+
</dependency>
70+
</dependencies>
71+
</profile>
72+
</profiles>
73+
74+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2015-2021 the original author or authors.
3+
*
4+
* All rights reserved. This program and the accompanying materials are
5+
* made available under the terms of the Eclipse Public License v2.0 which
6+
* accompanies this distribution and is available at
7+
*
8+
* https://www.eclipse.org/legal/epl-v20.html
9+
*/
10+
11+
package com.example.project;
12+
13+
import static org.junit.jupiter.api.Assertions.assertEquals;
14+
15+
import org.junit.jupiter.api.DisplayName;
16+
import org.junit.jupiter.api.Test;
17+
import org.junit.jupiter.params.ParameterizedTest;
18+
import org.junit.jupiter.params.provider.CsvSource;
19+
20+
class DummyTests {
21+
22+
@Test
23+
void test() {
24+
}
25+
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2015-2022 the original author or authors.
3+
*
4+
* All rights reserved. This program and the accompanying materials are
5+
* made available under the terms of the Eclipse Public License v2.0 which
6+
* accompanies this distribution and is available at
7+
*
8+
* https://www.eclipse.org/legal/epl-v20.html
9+
*/
10+
11+
package platform.tooling.support.tests;
12+
13+
import static org.assertj.core.api.Assertions.assertThat;
14+
import static org.junit.jupiter.api.Assertions.assertEquals;
15+
import static org.junit.jupiter.api.Assertions.assertFalse;
16+
import static org.junit.jupiter.api.Assertions.assertTrue;
17+
import static platform.tooling.support.Helper.TOOL_TIMEOUT;
18+
19+
import java.io.IOException;
20+
import java.nio.file.Files;
21+
22+
import org.junit.jupiter.params.ParameterizedTest;
23+
import org.junit.jupiter.params.provider.CsvSource;
24+
import org.opentest4j.TestAbortedException;
25+
26+
import platform.tooling.support.Helper;
27+
import platform.tooling.support.MavenRepo;
28+
import platform.tooling.support.Request;
29+
30+
/**
31+
* @since 1.9.2
32+
*/
33+
class MavenSurefireCompatibilityTests {
34+
35+
@ParameterizedTest
36+
@CsvSource(delimiter = '|', nullValues = "<none>", textBlock = """
37+
2.22.2 | --activate-profiles=manual-platform-dependency
38+
3.0.0-M4 | <none>
39+
""")
40+
void testMavenSurefireCompatibilityProject(String surefireVersion, String extraArg) throws IOException {
41+
var extraArgs = extraArg == null ? new Object[0] : new Object[] { extraArg };
42+
var request = Request.builder() //
43+
.setTool(Request.maven()) //
44+
.setProject("maven-surefire-compatibility") //
45+
.addArguments("-Dmaven.repo=" + MavenRepo.dir()) //
46+
.addArguments("-Dsurefire.version=" + surefireVersion) //
47+
.addArguments("--update-snapshots", "--batch-mode", "test") //
48+
.addArguments(extraArgs) //
49+
.setTimeout(TOOL_TIMEOUT) //
50+
.setJavaHome(Helper.getJavaHome("8").orElseThrow(TestAbortedException::new)) //
51+
.build();
52+
53+
var result = request.run();
54+
55+
assertFalse(result.isTimedOut(), () -> "tool timed out: " + result);
56+
57+
assertEquals(0, result.getExitCode());
58+
assertEquals("", result.getOutput("err"));
59+
60+
var output = result.getOutputLines("out");
61+
assertTrue(output.contains("[INFO] BUILD SUCCESS"));
62+
assertTrue(output.contains("[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0"));
63+
64+
var targetDir = Request.WORKSPACE.resolve(request.getWorkspace()).resolve("target");
65+
try (var stream = Files.list(targetDir)) {
66+
assertThat(stream.filter(file -> file.getFileName().toString().startsWith("junit-platform-unique-ids"))) //
67+
.hasSize(1);
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)