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 2017/12/19 02:03:24 UTC

maven-surefire git commit: [SUREFIRE-1453] Allow to specify non existant classes as groups

Repository: maven-surefire
Updated Branches:
  refs/heads/master a85d3276d -> 9826145df


[SUREFIRE-1453] Allow to specify non existant classes as groups


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/9826145d
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/9826145d
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/9826145d

Branch: refs/heads/master
Commit: 9826145dfea0e23894e2df48f64dd20a5d465c85
Parents: a85d327
Author: Enrico Olivelli <eo...@apache.org>
Authored: Fri Dec 15 08:53:27 2017 +0100
Committer: Tibor17 <ti...@apache.org>
Committed: Tue Dec 19 00:01:00 2017 +0100

----------------------------------------------------------------------
 .../group/match/SingleGroupMatcher.java         |   5 +-
 .../group/match/SingleGroupMatcherTest.java     |   7 ++
 .../surefire/its/JUnit48TestCategoriesIT.java   | 112 ++++++++++++++-----
 3 files changed, 93 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/9826145d/surefire-grouper/src/main/java/org/apache/maven/surefire/group/match/SingleGroupMatcher.java
----------------------------------------------------------------------
diff --git a/surefire-grouper/src/main/java/org/apache/maven/surefire/group/match/SingleGroupMatcher.java b/surefire-grouper/src/main/java/org/apache/maven/surefire/group/match/SingleGroupMatcher.java
index 65181fa..7f5f247 100644
--- a/surefire-grouper/src/main/java/org/apache/maven/surefire/group/match/SingleGroupMatcher.java
+++ b/surefire-grouper/src/main/java/org/apache/maven/surefire/group/match/SingleGroupMatcher.java
@@ -139,7 +139,10 @@ public class SingleGroupMatcher
         }
         catch ( ClassNotFoundException e )
         {
-            throw new RuntimeException( "Unable to load category: " + enabled, e );
+            // class is not available at runtime, for instance this would happen in reactor projects
+            // in which not all modules have the required class on the classpath/module path
+            System.out.println( "[WARNING] Couldn't load group class '" + enabled + "' in Surefire|Failsafe plugin. "
+                    + "The group class is ignored!" );
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/9826145d/surefire-grouper/src/test/java/org/apache/maven/surefire/group/match/SingleGroupMatcherTest.java
----------------------------------------------------------------------
diff --git a/surefire-grouper/src/test/java/org/apache/maven/surefire/group/match/SingleGroupMatcherTest.java b/surefire-grouper/src/test/java/org/apache/maven/surefire/group/match/SingleGroupMatcherTest.java
index c9f12f1..31d959f 100644
--- a/surefire-grouper/src/test/java/org/apache/maven/surefire/group/match/SingleGroupMatcherTest.java
+++ b/surefire-grouper/src/test/java/org/apache/maven/surefire/group/match/SingleGroupMatcherTest.java
@@ -37,6 +37,13 @@ public class SingleGroupMatcherTest
         assertTrue( matcher.enabled( SingleGroupMatcher.class ) );
     }
 
+    public void testMatchUnknownClass()
+    {
+        SingleGroupMatcher matcher = new SingleGroupMatcher( "BadClass" );
+        matcher.loadGroupClasses( Thread.currentThread().getContextClassLoader() );
+        assertTrue( matcher.enabled( "BadClass" ) );
+    }
+
     public void testMatchClassNameWithoutPackage()
     {
         SingleGroupMatcher matcher = new SingleGroupMatcher( SingleGroupMatcher.class.getSimpleName() );

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/9826145d/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit48TestCategoriesIT.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit48TestCategoriesIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit48TestCategoriesIT.java
index 70b614f..fdb56f7 100644
--- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit48TestCategoriesIT.java
+++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit48TestCategoriesIT.java
@@ -19,13 +19,10 @@ package org.apache.maven.surefire.its;
  * under the License.
  */
 
-import org.apache.maven.it.VerificationException;
 import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
 import org.apache.maven.surefire.its.fixture.SurefireLauncher;
 import org.junit.Test;
 
-import java.io.IOException;
-
 /**
  * Test project using "groups" support
  *
@@ -33,61 +30,116 @@ import java.io.IOException;
  * @author <a href="mailto:krosenvold@apache.org">Kristian Rosenvold</a>
  */
 public class JUnit48TestCategoriesIT
-    extends SurefireJUnit4IntegrationTestCase
+        extends SurefireJUnit4IntegrationTestCase
 {
     @Test
     public void testCategoriesAB()
-        throws Exception
     {
         runAB( unpacked() );
     }
 
-
     @Test
     public void testCategoriesABForkAlways()
-        throws Exception
     {
-        runAB( unpacked() );
+        runAB( unpacked().forkAlways() );
     }
 
     @Test
-    public void testCategoriesAC()
-        throws Exception
+    public void testCategoriesACFullyQualifiedClassName()
     {
-        runAC( unpacked() );
+        runACFullyQualifiedClassName( unpacked() );
     }
 
-    private void runAB( SurefireLauncher unpacked )
-            throws VerificationException
+    @Test
+    public void testCategoriesACFullyQualifiedClassNameForkAlways()
     {
-        unpacked.executeTest().verifyErrorFreeLog().assertTestSuiteResults( 3, 0, 0, 0 ).verifyTextInLog(
-                "catA: 1" ).verifyTextInLog( "catB: 1" ).verifyTextInLog( "catC: 0" ).verifyTextInLog( "catNone: 0" );
+        runACFullyQualifiedClassName( unpacked().forkAlways() );
     }
 
     @Test
-    public void testCategoriesACForkAlways()
-        throws Exception
+    public void testCategoriesACClassNameSuffix()
     {
-        runAC( unpacked().forkAlways() );
+        runACClassNameSuffix( unpacked() );
     }
 
+    @Test
+    public void testCategoriesACClassNameSuffixForkAlways()
+    {
+        runACClassNameSuffix( unpacked().forkAlways() );
+    }
 
-    private void runAC( SurefireLauncher surefireLauncher )
-        throws Exception
+    @Test
+    public void testCategoriesBadCategory()
     {
-        surefireLauncher.groups(
-            "junit4.CategoryA,junit4.CategoryC" ).executeTest().verifyErrorFreeLog().assertTestSuiteResults( 6, 0, 0,
-                                                                                                             0 ).verifyTextInLog(
-            "catA: 1" ).verifyTextInLog( "catB: 0" ).verifyTextInLog( "catC: 1" ).verifyTextInLog(
-            "catNone: 0" ).verifyTextInLog( "mA: 1" ).verifyTextInLog(
-            "mB: 1" ) // This seems questionable !? The class is annotated with category C and method with B
-            .verifyTextInLog( "mC: 1" ).verifyTextInLog( "CatNone: 1" );
+        runBadCategory( unpacked() );
     }
 
-    private SurefireLauncher unpacked()
-        throws VerificationException, IOException
+    @Test
+    public void testBadCategoryForkAlways()
     {
-        return unpack( "/junit48-categories" ); // .debugSurefireFork();
+        runBadCategory( unpacked().forkAlways() );
     }
 
+    private static void runAB( SurefireLauncher unpacked )
+    {
+        unpacked.executeTest()
+                .verifyErrorFreeLog()
+                .assertTestSuiteResults( 3, 0, 0, 0 )
+                .verifyTextInLog( "catA: 1" )
+                .verifyTextInLog( "catB: 1" )
+                .verifyTextInLog( "catC: 0" )
+                .verifyTextInLog( "catNone: 0" );
+    }
+
+    private static void runACClassNameSuffix( SurefireLauncher unpacked )
+    {
+        unpacked.groups( "CategoryA,CategoryC" )
+                .executeTest()
+                .verifyErrorFreeLog()
+                .assertTestSuiteResults( 6, 0, 0, 0 )
+                .verifyTextInLog( "catA: 1" )
+                .verifyTextInLog( "catB: 0" )
+                .verifyTextInLog( "catC: 1" )
+                .verifyTextInLog( "catNone: 0" )
+                .verifyTextInLog( "mA: 1" )
+
+                // This seems questionable !? The class is annotated with category C and method with B
+                .verifyTextInLog( "mB: 1" )
+
+                .verifyTextInLog( "mC: 1" )
+                .verifyTextInLog( "CatNone: 1" );
+    }
+
+    private static void runACFullyQualifiedClassName( SurefireLauncher unpacked )
+    {
+        unpacked.groups( "junit4.CategoryA,junit4.CategoryC" )
+                .executeTest()
+                .verifyErrorFreeLog()
+                .assertTestSuiteResults( 6, 0, 0, 0 )
+                .verifyTextInLog( "catA: 1" )
+                .verifyTextInLog( "catB: 0" )
+                .verifyTextInLog( "catC: 1" )
+                .verifyTextInLog( "catNone: 0" )
+                .verifyTextInLog( "mA: 1" )
+
+                // This seems questionable !? The class is annotated with category C and method with B
+                .verifyTextInLog( "mB: 1" )
+
+                .verifyTextInLog( "mC: 1" )
+                .verifyTextInLog( "CatNone: 1" );
+    }
+
+    private static void runBadCategory( SurefireLauncher unpacked )
+    {
+        unpacked.failIfNoTests( false )
+                .groups( "BadCategory" )
+                .executeTest()
+                .verifyErrorFreeLog();
+    }
+
+    private SurefireLauncher unpacked()
+    {
+        return unpack( "/junit48-categories" );
+        // .debugSurefireFork();
+    }
 }