Skip to content

Commit

Permalink
[SUREFIRE-2024] Replace testng-junit5 by testng-engine
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Mar 27, 2022
1 parent 6e60b03 commit 1c73dc5
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 77 deletions.
22 changes: 8 additions & 14 deletions maven-surefire-plugin/src/site/apt/examples/junit-platform.apt.vm
Expand Up @@ -79,7 +79,6 @@ Using JUnit 5 Platform
JUnit5 API artifact and your test sources become isolated from engine. In these chapters you will see how you can
segregate, combine, select the APIs and Engines miscellaneous way. You can find integration tests
{{{https://github.com/apache/maven-surefire/tree/master/surefire-its/src/test/resources/junit-4-5}with JUnit4/5}},
{{{https://github.com/apache/maven-surefire/tree/master/surefire-its/src/test/resources/junit5-testng}with JUnit5/TestNG}}
and {{{https://github.com/apache/maven-surefire/tree/master/surefire-its/src/test/resources/junit5-runner}with the JUnit4 Runner for Jupiter tests}}.
(See the Maven profiles.)

Expand Down Expand Up @@ -347,37 +346,32 @@ 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/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>
<groupId>org.junit.support</groupId>
<artifactId>testng-engine</artifactId>
<version>1.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>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Expand Up @@ -93,6 +93,17 @@ public void selectJUnit5()
"Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider" );
}

@Test
public void testNgOnlyWithJUnitPlatform()
{
unpack( "junit5-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 @@ -104,7 +115,6 @@ public void testNgWithJupiterApi()
.verifyTextInLog( "Running pkg.TestNGTest" )
.verifyTextInLog(
"Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider" );

}

@Test
Expand Down
65 changes: 65 additions & 0 deletions surefire-its/src/test/resources/junit5-testng-only/pom.xml
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->

<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>

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

<description>Project with only TestNG tests executed by JUnit Platform</description>

<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.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.support</groupId>
<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>

</project>
@@ -0,0 +1,10 @@
package pkg;

import org.testng.annotations.Test;

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

}
}
124 changes: 62 additions & 62 deletions surefire-its/src/test/resources/junit5-testng/pom.xml
Expand Up @@ -21,74 +21,74 @@
<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.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.support</groupId>
<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>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>
</dependencies>
</profile>
<profile>
<id>junit5-api</id>
<dependencies>
<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>
<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>

0 comments on commit 1c73dc5

Please sign in to comment.