You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2020/05/10 22:13:38 UTC

[maven-surefire] branch SUREFIRE-1787 updated: new integration tests and documentation

This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a commit to branch SUREFIRE-1787
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git


The following commit(s) were added to refs/heads/SUREFIRE-1787 by this push:
     new f5f41a8  new integration tests and documentation
f5f41a8 is described below

commit f5f41a87890996f9b4a1adedaac83df9003b648f
Author: tibordigana <ti...@apache.org>
AuthorDate: Mon May 11 00:13:31 2020 +0200

    new integration tests and documentation
---
 .../src/site/apt/examples/junit-platform.apt.vm    | 241 ++++++++++++++++++++-
 .../surefire/its/jiras/Surefire1787JUnit5IT.java   |  30 +++
 surefire-its/src/test/resources/junit-4-5/pom.xml  |  19 ++
 .../src/test/resources/junit5-runner/pom.xml       |  22 +-
 .../src/test/resources/junit5-testng/pom.xml       |  26 ++-
 5 files changed, 329 insertions(+), 9 deletions(-)

diff --git a/maven-surefire-plugin/src/site/apt/examples/junit-platform.apt.vm b/maven-surefire-plugin/src/site/apt/examples/junit-platform.apt.vm
index d2d49fc..ef5c014 100644
--- a/maven-surefire-plugin/src/site/apt/examples/junit-platform.apt.vm
+++ b/maven-surefire-plugin/src/site/apt/examples/junit-platform.apt.vm
@@ -74,12 +74,25 @@ Using JUnit 5 Platform
   see the {{{https://junit.org/junit5/}JUnit 5 web site}}
   and the {{{https://junit.org/junit5/docs/current/user-guide/}JUnit 5 User Guide}}.
 
-* Smart Resolution of Jupiter Engine and Vintage Engine for JUnit4 (since plugin version 3.0.0-M4)
+* Smart Resolution of Jupiter Engine and Vintage Engine for JUnit4
 
-  JUnit5 API artifact and your test sources become isolated from engine.
+  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.)
 
-  Normally the developer does not want to access internal classes of JUnit5 engine (e.g. <<<5.4.0>>>). In this example
-  the POM has only Jupiter API dependency in test classpath.
+** How to run only one API
+
+  Normally, the developer does not want to access internal classes of JUnit5 engine (e.g. <<<5.4.0>>>).
+  In the next chapters you can find your way to use the Jupiter or JUnit5 API where the plugin would resolve the engine.
+
+*** Jupiter API in test dependencies
+
+  In this example the POM has only Jupiter API dependency in test classpath. The plugin will resolve and download
+  the <<<junit-jupiter-engine>>> with the version related to the version of <<<junit-jupiter-api>>>. Similar principles
+  can be found in the following chapters as well.
 
 +---+
 <dependencies>
@@ -108,6 +121,8 @@ Using JUnit 5 Platform
 ...
 +---+
 
+*** API-Engine versions segregation
+
   In the following example the engine artifact appears in plugin dependencies and the engine is resolved by the plugin
   and downloaded from a remote repository for plugins. You may want to update the version of engine with fixed bugs in
   <<<5.3.2>>> but the API version <<<5.3.0>>> stays intact!
@@ -145,8 +160,11 @@ Using JUnit 5 Platform
 ...
 +---+
 
+*** JUnit4 API in test dependencies
 
-  Similar with JUnit4 in test dependencies of your project POM. The Vintage engine artifact is in plugin dependencies.
+  This is similar example with JUnit4 in test dependencies of your project POM.
+  The Vintage engine artifact has to be in the plugin dependencies; otherwise the plugin would use
+  <<<surefire-junit4>>> provider instead of the <<<surefire-junit-platform>>> provider.
 
 +---+
 <dependencies>
@@ -180,6 +198,219 @@ Using JUnit 5 Platform
 ...
 +---+
 
+** How to run multiple APIs or Engines
+
+  In the following example you can use both JUnit4 and JUnit5 tests.
+
+*** Jupiter API and JUnit4
+
+  Once you define any JUnit5 API in the dependencies, the provider <<<surefire-junit-platform>>> is selected and
+  you can always add the JUnit4 dependency.
+
++---+
+<dependencies>
+    <dependency>
+        <groupId>org.junit.jupiter</groupId>
+        <artifactId>junit-jupiter-api</artifactId>
+        <version>5.6.2</version>
+        <scope>test</scope>
+    </dependency>
+    <dependency>
+        <groupId>junit</groupId>
+        <artifactId>junit</artifactId>
+        <version>4.13</version>
+        <scope>test</scope>
+    </dependency>
+</dependencies>
++---+
+
+*** Jupiter API and Vintage Engine
+
++---+
+<dependencies>
+    <dependency>
+        <groupId>org.junit.jupiter</groupId>
+        <artifactId>junit-jupiter-api</artifactId>
+        <version>5.6.2</version>
+        <scope>test</scope>
+    </dependency>
+    <dependency>
+        <groupId>org.junit.vintage</groupId>
+        <artifactId>junit-vintage-engine</artifactId>
+        <version>5.6.2</version>
+        <scope>test</scope>
+    </dependency>
+</dependencies>
++---+
+
+*** Jupiter and Vintage Engine
+
++---+
+<dependencies>
+    <dependency>
+        <groupId>org.junit.jupiter</groupId>
+        <artifactId>junit-jupiter-engine</artifactId>
+        <version>5.6.2</version>
+        <scope>test</scope>
+    </dependency>
+    <dependency>
+        <groupId>org.junit.vintage</groupId>
+        <artifactId>junit-vintage-engine</artifactId>
+        <version>5.6.2</version>
+        <scope>test</scope>
+    </dependency>
+</dependencies>
++---+
+
+** Select engine and use multiple APIs
+
+  In these examples you use both API, i.e. Jupiter and JUnit4, in the test dependencies but you want to select
+  the engine via plugin dependencies.
+
+*** Select Jupiter
+
+    Here your tests import the packages from JUnit4 and Jupiter but you want to select only one Maven profile
+    with JUnit4 tests.
+
++---+
+<dependencies>
+    <dependency>
+        <groupId>org.junit.jupiter</groupId>
+        <artifactId>junit-jupiter-api</artifactId>
+        <version>5.6.2</version>
+        <scope>test</scope>
+    </dependency>
+    <dependency>
+        <groupId>junit</groupId>
+        <artifactId>junit</artifactId>
+        <version>4.13</version>
+        <scope>test</scope>
+    </dependency>
+</dependencies>
+<profile>
+    <id>select-junit5</id>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <dependencies>
+                    <dependency>
+                        <groupId>org.junit.jupiter</groupId>
+                        <artifactId>junit-jupiter-engine</artifactId>
+                        <version>5.6.2</version>
+                    </dependency>
+                </dependencies>
+            </plugin>
+        </plugins>
+    </build>
+</profile>
++---+
+
+*** Select JUnit4
+
+  Here your tests import the packages from JUnit4 and Jupiter but you want to select only one Maven profile
+  with Jupiter tests.
+
++---+
+<dependencies>
+    <dependency>
+        <groupId>org.junit.jupiter</groupId>
+        <artifactId>junit-jupiter-api</artifactId>
+        <version>5.6.2</version>
+        <scope>test</scope>
+    </dependency>
+    <dependency>
+        <groupId>junit</groupId>
+        <artifactId>junit</artifactId>
+        <version>4.13</version>
+        <scope>test</scope>
+    </dependency>
+</dependencies>
+<profile>
+    <id>select-junit4</id>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <dependencies>
+                    <dependency>
+                        <groupId>org.junit.vintage</groupId>
+                        <artifactId>junit-vintage-engine</artifactId>
+                        <version>5.6.2</version>
+                    </dependency>
+                </dependencies>
+            </plugin>
+        </plugins>
+    </build>
+</profile>
++---+
+
+** How to run TestNG tests within Jupiter engine
+
+  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}}.
+
++---+
+<dependencies>
+    <dependency>
+        <groupId>org.testng</groupId>
+        <artifactId>testng</artifactId>
+        <version>7.1.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>
+        <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>>>.
+
+** JUnit Runner
+
+  The JUnit4 library has the {{{https://junit.org/junit4/javadoc/latest/src-html/org/junit/runner/Runner.html}Runner}}
+  implemented in the JUnit5's artifact <<<junit-platform-runner>>>.
+
+  For more information see this
+  {{{https://github.com/apache/maven-surefire/tree/master/surefire-its/src/test/resources/junit5-runner}example}}.
+
++---+
+<dependencies>
+    <dependency>
+        <groupId>org.junit.jupiter</groupId>
+        <artifactId>junit-jupiter-engine</artifactId>
+        <version>5.6.2</version>
+        <scope>test</scope>
+    </dependency>
+    <dependency>
+        <groupId>org.junit.platform</groupId>
+        <artifactId>junit-platform-runner</artifactId>
+        <version>1.6.2</version>
+        <scope>test</scope>
+    </dependency>
+</dependencies>
++---+
+
 * Provider Selection
 
    If nothing is configured, Surefire detects which JUnit version to use by the following algorithm:
diff --git a/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1787JUnit5IT.java b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1787JUnit5IT.java
index 0423993..eab5733 100644
--- a/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1787JUnit5IT.java
+++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1787JUnit5IT.java
@@ -79,4 +79,34 @@ public class Surefire1787JUnit5IT extends SurefireJUnit4IntegrationTestCase
             .verifyErrorFree( 1 )
             .verifyTextInLog( "Running pkg.JUnit5Test" );
     }
+
+    @Test
+    public void testNgWithJupiterApi()
+    {
+        unpack( "junit5-testng" )
+            .activateProfile( "junit5-api" )
+            .executeTest()
+            .verifyErrorFree( 2 )
+            .verifyTextInLog( "Running pkg.JUnit5Test" )
+            .verifyTextInLog( "Running pkg.TestNGTest" );
+    }
+
+    @Test
+    public void testNgWithJupiterEngine()
+    {
+        unpack( "junit5-testng" )
+            .activateProfile( "junit5-engine" )
+            .executeTest()
+            .verifyErrorFree( 2 )
+            .verifyTextInLog( "Running pkg.JUnit5Test" )
+            .verifyTextInLog( "Running pkg.TestNGTest" );
+    }
+
+    @Test
+    public void junit4Runner()
+    {
+        unpack( "junit5-runner" )
+            .executeTest()
+            .verifyErrorFreeLog();
+    }
 }
diff --git a/surefire-its/src/test/resources/junit-4-5/pom.xml b/surefire-its/src/test/resources/junit-4-5/pom.xml
index 546b8fc..5f6a5a4 100644
--- a/surefire-its/src/test/resources/junit-4-5/pom.xml
+++ b/surefire-its/src/test/resources/junit-4-5/pom.xml
@@ -1,4 +1,23 @@
 <?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">
diff --git a/surefire-its/src/test/resources/junit5-runner/pom.xml b/surefire-its/src/test/resources/junit5-runner/pom.xml
index a8eff6c..64a1bf6 100644
--- a/surefire-its/src/test/resources/junit5-runner/pom.xml
+++ b/surefire-its/src/test/resources/junit5-runner/pom.xml
@@ -1,4 +1,23 @@
 <?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">
@@ -9,6 +28,7 @@
     <version>1.0-SNAPSHOT</version>
 
     <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <maven.compiler.testSource>1.8</maven.compiler.testSource>
         <maven.compiler.testTarget>1.8</maven.compiler.testTarget>
     </properties>
@@ -34,7 +54,7 @@
                 <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
                     <artifactId>maven-surefire-plugin</artifactId>
-                    <version>3.0.0-SNAPSHOT</version>
+                    <version>${surefire.version}</version>
                     <configuration>
                         <test>JUnit5Tests</test>
                     </configuration>
diff --git a/surefire-its/src/test/resources/junit5-testng/pom.xml b/surefire-its/src/test/resources/junit5-testng/pom.xml
index 6bf6829..bc61240 100644
--- a/surefire-its/src/test/resources/junit5-testng/pom.xml
+++ b/surefire-its/src/test/resources/junit5-testng/pom.xml
@@ -1,4 +1,23 @@
 <?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">
@@ -9,6 +28,7 @@
     <version>1.0-SNAPSHOT</version>
 
     <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <maven.compiler.testSource>1.8</maven.compiler.testSource>
         <maven.compiler.testTarget>1.8</maven.compiler.testTarget>
     </properties>
@@ -40,7 +60,7 @@
                 <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
                     <artifactId>maven-surefire-plugin</artifactId>
-                    <version>3.0.0-SNAPSHOT</version>
+                    <version>${surefire.version}</version>
                 </plugin>
             </plugins>
         </pluginManagement>
@@ -48,7 +68,7 @@
 
     <profiles>
         <profile>
-            <id>both-engines</id>
+            <id>junit5-engine</id>
             <dependencies>
                 <dependency>
                     <groupId>org.junit.jupiter</groupId>
@@ -59,7 +79,7 @@
             </dependencies>
         </profile>
         <profile>
-            <id>both-api</id>
+            <id>junit5-api</id>
             <dependencies>
                 <dependency>
                     <groupId>org.junit.jupiter</groupId>