Skip to content

Commit 92b9061

Browse files
[SUREFIRE-2024] Replace testng-junit5 by testng-engine (#500)
1 parent 25425c3 commit 92b9061

File tree

4 files changed

+117
-82
lines changed

4 files changed

+117
-82
lines changed

maven-surefire-plugin/src/site/apt/examples/junit-platform.apt.vm

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -349,44 +349,33 @@ Using JUnit 5 Platform
349349
</profile>
350350
+---+
351351

352-
** How to run TestNG tests within Jupiter engine
352+
** How to run TestNG tests within the JUnit Platform
353353

354354
You can run TestNG tests combined with JUnit5 tests.
355355

356356
For more information see this
357-
{{{https://github.com/apache/maven-surefire/tree/master/surefire-its/src/test/resources/junit5-testng}example}}.
357+
{{{https://github.com/apache/maven-surefire/tree/master/surefire-its/src/test/resources/junit5-testng}example}}
358+
and {{{https://github.com/junit-team/testng-engine}TestNG Engine for the JUnit Platform}}.
358359

359360
+---+
360361
<dependencies>
361362
<dependency>
362363
<groupId>org.testng</groupId>
363364
<artifactId>testng</artifactId>
364-
<version>7.1.0</version>
365+
<version>7.4.0</version>
365366
<scope>test</scope>
366367
</dependency>
367368
<dependency>
368-
<groupId>com.github.testng-team</groupId>
369-
<artifactId>testng-junit5</artifactId>
370-
<version>0.0.1</version>
371-
<scope>test</scope>
372-
<exclusions>
373-
<exclusion>
374-
<groupId>org.junit.platform</groupId>
375-
<artifactId>junit-platform-engine</artifactId>
376-
</exclusion>
377-
</exclusions>
378-
</dependency>
379-
<dependency>
380-
<groupId>org.junit.jupiter</groupId>
381-
<artifactId>junit-jupiter-api</artifactId>
382-
<version>5.6.2</version>
369+
<groupId>org.junit.support</groupId>
370+
<artifactId>testng-engine</artifactId>
371+
<version>1.0.1</version>
383372
<scope>test</scope>
384373
</dependency>
385374
</dependencies>
386375
+---+
387376

388377
The Maven does not take any responsibility for broken compatibilities in this case and the responsibility for
389-
the dependency <<<com.github.testng-team:testng-junit5>>>.
378+
the dependency <<<org.junit.support:testng-engine>>>.
390379

391380
** JUnit Runner
392381

surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1787JUnit5IT.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ public void selectJUnit5()
9696
"Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider" );
9797
}
9898

99+
@Test
100+
public void testNg()
101+
{
102+
unpack( "junit5-testng" )
103+
.activateProfile( "testng-only" )
104+
.executeTest()
105+
.verifyErrorFree( 1 )
106+
.verifyTextInLog( "Running pkg.TestNGTest" )
107+
.verifyTextInLog(
108+
"Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider" );
109+
}
110+
99111
@Test
100112
public void testNgWithJupiterApi()
101113
{
@@ -107,7 +119,6 @@ public void testNgWithJupiterApi()
107119
.verifyTextInLog( "Running pkg.TestNGTest" )
108120
.verifyTextInLog(
109121
"Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider" );
110-
111122
}
112123

113124
@Test

surefire-its/src/test/resources/junit5-testng/pom.xml

Lines changed: 96 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -21,74 +21,109 @@
2121
<project xmlns="http://maven.apache.org/POM/4.0.0"
2222
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2323
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
24-
<modelVersion>4.0.0</modelVersion>
24+
<modelVersion>4.0.0</modelVersion>
2525

26-
<groupId>org.example</groupId>
27-
<artifactId>testng-junit5</artifactId>
28-
<version>1.0-SNAPSHOT</version>
26+
<groupId>org.example</groupId>
27+
<artifactId>testng-junit5</artifactId>
28+
<version>1.0-SNAPSHOT</version>
2929

30-
<properties>
31-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
32-
<maven.compiler.source>${java.specification.version}</maven.compiler.source>
33-
<maven.compiler.target>${java.specification.version}</maven.compiler.target>
34-
</properties>
30+
<description>Project with mixed TestNG and JUnit5 tests.</description>
3531

36-
<dependencies>
32+
<properties>
33+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
34+
<maven.compiler.source>${java.specification.version}</maven.compiler.source>
35+
<maven.compiler.target>${java.specification.version}</maven.compiler.target>
36+
</properties>
37+
38+
<dependencies>
39+
<dependency>
40+
<groupId>org.testng</groupId>
41+
<artifactId>testng</artifactId>
42+
<version>7.5</version>
43+
<scope>test</scope>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.junit.support</groupId>
47+
<artifactId>testng-engine</artifactId>
48+
<version>1.0.1</version>
49+
<scope>test</scope>
50+
</dependency>
51+
</dependencies>
52+
53+
<build>
54+
<pluginManagement>
55+
<plugins>
56+
<plugin>
57+
<groupId>org.apache.maven.plugins</groupId>
58+
<artifactId>maven-surefire-plugin</artifactId>
59+
<version>${surefire.version}</version>
60+
</plugin>
61+
</plugins>
62+
</pluginManagement>
63+
</build>
64+
65+
<profiles>
66+
<profile>
67+
<id>testng-only</id>
68+
<build>
69+
<plugins>
70+
<plugin>
71+
<groupId>org.apache.maven.plugins</groupId>
72+
<artifactId>maven-compiler-plugin</artifactId>
73+
<configuration>
74+
<testIncludes>
75+
<!-- JUnit5Test.java ignored - Jupiter does not exist in dependencies. -->
76+
<testInclude>**/TestNGTest.java</testInclude>
77+
</testIncludes>
78+
</configuration>
79+
</plugin>
80+
</plugins>
81+
</build>
82+
</profile>
83+
<profile>
84+
<id>junit5-engine</id>
85+
<dependencies>
3786
<dependency>
38-
<groupId>org.testng</groupId>
39-
<artifactId>testng</artifactId>
40-
<version>7.1.0</version>
41-
<scope>test</scope>
87+
<groupId>org.junit.jupiter</groupId>
88+
<artifactId>junit-jupiter-engine</artifactId>
89+
<!-- TODO check with next version of testng-engine -->
90+
<!-- we have old junit-platform-commons:1.7.2 in dependency tree -->
91+
<version>5.7.2</version>
92+
<scope>test</scope>
4293
</dependency>
43-
<dependency>
44-
<groupId>com.github.testng-team</groupId>
45-
<artifactId>testng-junit5</artifactId>
46-
<version>0.0.1</version>
47-
<scope>test</scope>
94+
</dependencies>
95+
</profile>
96+
<profile>
97+
<id>junit5-api</id>
98+
<!--
99+
This exclusion avoids inconsistent versions combination: junit-platform-engine:1.7.2 and junit-jupiter-api:5.8.2.
100+
The surefire would add artifacts to the class path: junit-platform-*, junit-jupiter-engine, etc.
101+
-->
102+
<dependencyManagement>
103+
<dependencies>
104+
<dependency>
105+
<groupId>org.junit.support</groupId>
106+
<artifactId>testng-engine</artifactId>
48107
<exclusions>
49-
<exclusion>
50-
<groupId>org.junit.platform</groupId>
51-
<artifactId>junit-platform-engine</artifactId>
52-
</exclusion>
108+
<exclusion>
109+
<groupId>org.junit.platform</groupId>
110+
<artifactId>junit-platform-engine</artifactId>
111+
</exclusion>
53112
</exclusions>
113+
</dependency>
114+
</dependencies>
115+
</dependencyManagement>
116+
<dependencies>
117+
<dependency>
118+
<groupId>org.junit.jupiter</groupId>
119+
<artifactId>junit-jupiter-api</artifactId>
120+
<!-- junit-jupiter-api has junit-platform-commons as nearest definition -->
121+
<!-- so junit-platform-commons:1.8.2 wins ;-) -->
122+
<version>5.8.2</version>
123+
<scope>test</scope>
54124
</dependency>
55-
</dependencies>
56-
57-
<build>
58-
<pluginManagement>
59-
<plugins>
60-
<plugin>
61-
<groupId>org.apache.maven.plugins</groupId>
62-
<artifactId>maven-surefire-plugin</artifactId>
63-
<version>${surefire.version}</version>
64-
</plugin>
65-
</plugins>
66-
</pluginManagement>
67-
</build>
68-
69-
<profiles>
70-
<profile>
71-
<id>junit5-engine</id>
72-
<dependencies>
73-
<dependency>
74-
<groupId>org.junit.jupiter</groupId>
75-
<artifactId>junit-jupiter-engine</artifactId>
76-
<version>5.6.2</version>
77-
<scope>test</scope>
78-
</dependency>
79-
</dependencies>
80-
</profile>
81-
<profile>
82-
<id>junit5-api</id>
83-
<dependencies>
84-
<dependency>
85-
<groupId>org.junit.jupiter</groupId>
86-
<artifactId>junit-jupiter-api</artifactId>
87-
<version>5.6.2</version>
88-
<scope>test</scope>
89-
</dependency>
90-
</dependencies>
91-
</profile>
92-
</profiles>
125+
</dependencies>
126+
</profile>
127+
</profiles>
93128

94129
</project>

surefire-its/src/test/resources/junit5-testng/src/test/java/pkg/JUnit5Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class JUnit5Test {
66
@Test
7-
public void test() {
7+
void test() {
88

99
}
1010
}

0 commit comments

Comments
 (0)