Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SUREFIRE-2024] Replace testng-junit5 by testng-engine #500

Merged
merged 2 commits into from Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 8 additions & 19 deletions maven-surefire-plugin/src/site/apt/examples/junit-platform.apt.vm
Expand Up @@ -349,44 +349,33 @@ Using JUnit 5 Platform
</profile>
+---+

** How to run TestNG tests within Jupiter engine
** How to run TestNG tests within the JUnit Platform

You can run TestNG tests combined with JUnit5 tests.

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

+---+
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.1.0</version>
<version>7.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.testng-team</groupId>
<artifactId>testng-junit5</artifactId>
<version>0.0.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.2</version>
<groupId>org.junit.support</groupId>
<artifactId>testng-engine</artifactId>
<version>1.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>
+---+

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

** JUnit Runner

Expand Down
Expand Up @@ -96,6 +96,18 @@ public void selectJUnit5()
"Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider" );
}

@Test
public void testNg()
{
unpack( "junit5-testng" )
.activateProfile( "testng-only" )
.executeTest()
.verifyErrorFree( 1 )
.verifyTextInLog( "Running pkg.TestNGTest" )
.verifyTextInLog(
"Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider" );
}

@Test
public void testNgWithJupiterApi()
{
Expand All @@ -107,7 +119,6 @@ public void testNgWithJupiterApi()
.verifyTextInLog( "Running pkg.TestNGTest" )
.verifyTextInLog(
"Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider" );

}

@Test
Expand Down
157 changes: 96 additions & 61 deletions surefire-its/src/test/resources/junit5-testng/pom.xml
Expand Up @@ -21,74 +21,109 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>testng-junit5</artifactId>
<version>1.0-SNAPSHOT</version>
<groupId>org.example</groupId>
<artifactId>testng-junit5</artifactId>
<version>1.0-SNAPSHOT</version>

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

<dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>${java.specification.version}</maven.compiler.source>
<maven.compiler.target>${java.specification.version}</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.support</groupId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are missing the engine exclusion in this dependency.
In the previous revision, see the POM, the Jupiter version was 5.5.0, therefore we excluded it and the engine and api was removed as well. Adding it in the provider would mean that a new version of the engine and api would be consistent with another version.

Overriding the version of API in the profile junit5-api would mean that the original engine stays. That's not consistent.
So it's better to remove engine as a transitive dependency. The profile's responsibility would be to specify junit artifact.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If engine should be not as a transitive dependency form testng-engin we simply should report a issue for testng-engin not introduce workaround here.

You point me to archived project https://github.com/testng-team/testng-junit5

Now maintenanced is:
https://github.com/junit-team/testng-engine

<artifactId>testng-engine</artifactId>
<version>1.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>

<profiles>
<profile>
<id>testng-only</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<testIncludes>
<!-- JUnit5Test.java ignored - Jupiter does not exist in dependencies. -->
<testInclude>**/TestNGTest.java</testInclude>
</testIncludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>junit5-engine</id>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.1.0</version>
<scope>test</scope>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<!-- TODO check with next version of testng-engine -->
<!-- we have old junit-platform-commons:1.7.2 in dependency tree -->
<version>5.7.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.testng-team</groupId>
<artifactId>testng-junit5</artifactId>
<version>0.0.1</version>
<scope>test</scope>
</dependencies>
</profile>
<profile>
<id>junit5-api</id>
<!--
This exclusion avoids inconsistent versions combination: junit-platform-engine:1.7.2 and junit-jupiter-api:5.8.2.
The surefire would add artifacts to the class path: junit-platform-*, junit-jupiter-engine, etc.
-->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit.support</groupId>
<artifactId>testng-engine</artifactId>
<exclusions>
<exclusion>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
</exclusion>
<exclusion>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<!-- junit-jupiter-api has junit-platform-commons as nearest definition -->
<!-- so junit-platform-commons:1.8.2 wins ;-) -->
<version>5.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>

<profiles>
<profile>
<id>junit5-engine</id>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>junit5-api</id>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
</dependencies>
</profile>
</profiles>

</project>
Expand Up @@ -4,7 +4,7 @@

class JUnit5Test {
@Test
public void test() {
void test() {

}
}