Repository: maven-surefire Updated Branches: refs/heads/master 2338a582c -> 544591c9d
[SUREFIRE-1191] Run Single Test with Package Name Doesn't work Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/544591c9 Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/544591c9 Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/544591c9 Branch: refs/heads/master Commit: 544591c9d18966f514bb4273aa06deed186a6810 Parents: 2338a58 Author: Tibor17 <tibo...@lycos.com> Authored: Sun Dec 6 01:45:49 2015 +0100 Committer: Tibor17 <tibo...@lycos.com> Committed: Sun Dec 6 01:45:49 2015 +0100 ---------------------------------------------------------------------- .../apt/examples/inclusion-exclusion.apt.vm | 18 ++++++++ .../src/site/apt/examples/single-test.apt.vm | 21 +++++++-- .../maven/surefire/testset/ResolvedTest.java | 14 ++++++ .../surefire/testset/TestListResolver.java | 6 +++ .../surefire/testset/ResolvedTestTest.java | 12 ++++++ .../maven/surefire/its/TestSingleMethodIT.java | 45 +++++++++++++++----- .../common/junit48/FilterFactoryTest.java | 10 ++++- 7 files changed, 111 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/544591c9/maven-surefire-plugin/src/site/apt/examples/inclusion-exclusion.apt.vm ---------------------------------------------------------------------- diff --git a/maven-surefire-plugin/src/site/apt/examples/inclusion-exclusion.apt.vm b/maven-surefire-plugin/src/site/apt/examples/inclusion-exclusion.apt.vm index 6a21dca..9bca134 100644 --- a/maven-surefire-plugin/src/site/apt/examples/inclusion-exclusion.apt.vm +++ b/maven-surefire-plugin/src/site/apt/examples/inclusion-exclusion.apt.vm @@ -180,3 +180,21 @@ Inclusions and Exclusions of Tests The character (?) within non-regex pattern replaces one character in file name or path. The file extensions are not mandatory in non-regex patterns, and packages with slash can be used. The regex validates fully qualified class file. The regex supports '.class' file extension only. Note the regex comments, marked by (#) character, are unsupported. + +* Fully qualified class name + + As of ${thisPlugin} Plugin 2.19.1, the syntax with fully qualified class names or packages can be used, e.g.: + ++---+ + [...] + <include>my.package.*, another.package.*</include> + [...] + <exclude>my.package.???ExcludedTest, another.package.*ExcludedTest</exclude> + [...] ++---+ + + The character (?) replaces single character and (*) represents zero or more characters. + Multiple formats can be additionally combined. + This syntax can be used in parameters: <<<test>>>, <<<includes>>>, <<<excludes>>>, <<<includesFile>>>, <<<excludesFile>>>. + + http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/544591c9/maven-surefire-plugin/src/site/apt/examples/single-test.apt.vm ---------------------------------------------------------------------- diff --git a/maven-surefire-plugin/src/site/apt/examples/single-test.apt.vm b/maven-surefire-plugin/src/site/apt/examples/single-test.apt.vm index af75e17..4dcb67b 100644 --- a/maven-surefire-plugin/src/site/apt/examples/single-test.apt.vm +++ b/maven-surefire-plugin/src/site/apt/examples/single-test.apt.vm @@ -79,17 +79,16 @@ mvn -Dit.test=ITSquare,ITCi*le verify +---+ #{end} - << NOTE: Use syntax e.g. "foo/MyTest.java", "**/MyTest.java", "MyTest" for "test" parameter (see includes/excludes) - instead of fully qualified Java class names. >> + << NOTE: Use syntax e.g. "foo/MyTest.java", "**/MyTest.java", "MyTest" for "test" parameter (see includes/excludes). >> Running a Set of Methods in a Single Test Class As of Surefire 2.7.3, you can also run only a subset of the tests in a test class. << NOTE : This feature is supported only for Junit 4.x and TestNG. Use syntax e.g. "foo/MyTest.java", - "**/MyTest.java", "MyTest" for "test" parameter (see includes/excludes) instead of fully qualified Java class names. >> + "**/MyTest.java", "MyTest" for "test" parameter (see includes/excludes). >> - You must use the following syntax: + You should use the following syntax: #{if}(${project.artifactId}=="maven-surefire-plugin") +---+ @@ -151,3 +150,17 @@ mvn "-Dit.test=Basic*, !%regex[.*.Unstable.*], !%regex[.*.MyIT.class#one.*|two.* non-regex method pattern would become <<<#testMethod[*]>>>. If using the JUnit annotation <<<@Parameters(name="\{index\}: fib(\{0\})=\{1\}")>>> and selecting the index e.g. 5 in pattern, the non-regex method pattern would become <<<#testMethod[5:*]>>>. + +* Fully qualified class name + + As of ${thisPlugin} Plugin 2.19.1, the syntax with fully qualified class names or packages can be used, e.g.: + ++---+ +<test>my.package.???Test#testMethod, another.package.*</test> ++---+ + + The character (?) replaces single character and (*) represents zero or more characters. + Multiple formats can be additionally combined. + + + http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/544591c9/surefire-api/src/main/java/org/apache/maven/surefire/testset/ResolvedTest.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/testset/ResolvedTest.java b/surefire-api/src/main/java/org/apache/maven/surefire/testset/ResolvedTest.java index 558aaed..b0ef1ac 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/testset/ResolvedTest.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/testset/ResolvedTest.java @@ -305,6 +305,7 @@ public final class ResolvedTest if ( s != null && !isRegex ) { s = convertToPath( s ); + s = fromFullyQualifiedClass( s ); if ( s != null && !s.startsWith( WILDCARD_PATH_PREFIX ) ) { s = WILDCARD_PATH_PREFIX + s; @@ -334,4 +335,17 @@ public final class ResolvedTest { return SelectorUtils.REGEX_HANDLER_PREFIX + unwrapped + SelectorUtils.PATTERN_HANDLER_SUFFIX; } + + static String fromFullyQualifiedClass( String cls ) + { + if ( cls.endsWith( CLASS_FILE_EXTENSION ) ) + { + cls = cls.substring( 0, cls.length() - CLASS_FILE_EXTENSION.length() ); + return cls.replace( '.', '/' ) + CLASS_FILE_EXTENSION; + } + else + { + return cls.replace( '.', '/' ); + } + } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/544591c9/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestListResolver.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestListResolver.java b/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestListResolver.java index c54bd97..dccfdcb 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestListResolver.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestListResolver.java @@ -183,6 +183,12 @@ public class TestListResolver return shouldRun( toClassFileName( testClass ), methodName ); } + /** + * Returns {@code true} if satisfies {@code testClassFile} and {@code methodName} filter. + * + * @param testClassFile format must be e.g. "my/package/MyTest.class" including class extension; or null + * @param methodName real test-method name; or null + */ public boolean shouldRun( String testClassFile, String methodName ) { if ( isEmpty() || isBlank( testClassFile ) && isBlank( methodName ) ) http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/544591c9/surefire-api/src/test/java/org/apache/maven/surefire/testset/ResolvedTestTest.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/test/java/org/apache/maven/surefire/testset/ResolvedTestTest.java b/surefire-api/src/test/java/org/apache/maven/surefire/testset/ResolvedTestTest.java index 783209a..95cc812 100644 --- a/surefire-api/src/test/java/org/apache/maven/surefire/testset/ResolvedTestTest.java +++ b/surefire-api/src/test/java/org/apache/maven/surefire/testset/ResolvedTestTest.java @@ -46,4 +46,16 @@ public class ResolvedTestTest assertTrue( test.isRegexTestMethodPattern() ); assertTrue( test.isEmpty() ); } + + public void testFromFullyQualifiedClass() + { + String classFileName = ResolvedTest.fromFullyQualifiedClass( "my.package.MyTest" ); + assertEquals( "my/package/MyTest", classFileName ); + + classFileName = ResolvedTest.fromFullyQualifiedClass( "my.package.MyTest.class" ); + assertEquals( "my/package/MyTest.class", classFileName ); + + classFileName = ResolvedTest.fromFullyQualifiedClass( "my/package/MyTest.class" ); + assertEquals( "my/package/MyTest.class", classFileName ); + } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/544591c9/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestSingleMethodIT.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestSingleMethodIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestSingleMethodIT.java index d7b7088..9cc14fb 100644 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestSingleMethodIT.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestSingleMethodIT.java @@ -34,7 +34,7 @@ public class TestSingleMethodIT { private static final String RUNNING_WITH_PROVIDER47 = "parallel='none', perCoreThreadCount=true, threadCount=0"; - public OutputValidator singleMethod( String projectName, String... goals ) + public OutputValidator singleMethod( String projectName, String testToRun, String... goals ) throws Exception { SurefireLauncher launcher = unpack( projectName ); @@ -42,31 +42,35 @@ public class TestSingleMethodIT { launcher.addGoal( goal ); } - return launcher.showErrorStackTraces().debugLogging() - .executeTest() - .verifyErrorFreeLog() - .assertTestSuiteResults( 1, 0, 0, 0 ); + launcher.showErrorStackTraces().debugLogging(); + if ( testToRun != null ) + { + launcher.setTestToRun( testToRun ); + } + return launcher.executeTest() + .verifyErrorFreeLog() + .assertTestSuiteResults( 1, 0, 0, 0 ); } @Test public void testJunit44() throws Exception { - singleMethod( "junit44-single-method" ); + singleMethod( "junit44-single-method", null ); } @Test public void testJunit48Provider4() throws Exception { - singleMethod( "junit48-single-method", "-P surefire-junit4" ); + singleMethod( "junit48-single-method", null, "-P surefire-junit4" ); } @Test public void testJunit48Provider47() throws Exception { - singleMethod( "junit48-single-method", "-P surefire-junit47" ) + singleMethod( "junit48-single-method", null, "-P surefire-junit47" ) .verifyTextInLog( RUNNING_WITH_PROVIDER47 ); } @@ -86,14 +90,35 @@ public class TestSingleMethodIT public void testTestNg() throws Exception { - singleMethod( "testng-single-method" ); + singleMethod( "testng-single-method", null ); } @Test public void testTestNg5149() throws Exception { - singleMethod( "/testng-single-method-5-14-9" ); + singleMethod( "/testng-single-method-5-14-9", null ); + } + + @Test + public void fullyQualifiedJunit48Provider4() + throws Exception + { + singleMethod( "junit48-single-method", "junit4.BasicTest#testSuccessOne", "-P surefire-junit4" ); + } + + @Test + public void fullyQualifiedJunit48Provider47() + throws Exception + { + singleMethod("junit48-single-method", "junit4.BasicTest#testSuccessOne", "-P surefire-junit47"); + } + + @Test + public void fullyQualifiedTestNg() + throws Exception + { + singleMethod( "testng-single-method", "testng.BasicTest#testSuccessOne" ); } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/544591c9/surefire-providers/common-junit48/src/test/java/org/apache/maven/surefire/common/junit48/FilterFactoryTest.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-junit48/src/test/java/org/apache/maven/surefire/common/junit48/FilterFactoryTest.java b/surefire-providers/common-junit48/src/test/java/org/apache/maven/surefire/common/junit48/FilterFactoryTest.java index d3c280a..3618b39 100644 --- a/surefire-providers/common-junit48/src/test/java/org/apache/maven/surefire/common/junit48/FilterFactoryTest.java +++ b/surefire-providers/common-junit48/src/test/java/org/apache/maven/surefire/common/junit48/FilterFactoryTest.java @@ -999,7 +999,7 @@ public class FilterFactoryTest public void testIncludesExcludes() { Collection<String> inc = Arrays.asList( "**/NotIncludedByDefault.java", "**/*Test.java" ); - Collection<String> exc = Collections.singletonList( "**/DontRunTest.*" ); + Collection<String> exc = Collections.singletonList( "**/DontRunTest.class" ); TestListResolver resolver = new TestListResolver( inc, exc ); assertFalse( resolver.shouldRun( "org/test/DontRunTest.class", null ) ); assertTrue( resolver.shouldRun( "org/test/DefaultTest.class", null ) ); @@ -1012,4 +1012,12 @@ public class FilterFactoryTest TestListResolver resolver = new TestListResolver( "NotIncludedByDefault" ); assertTrue( resolver.shouldRun( "org/test/NotIncludedByDefault.class", null ) ); } + + @Test + public void testFullyQualifiedClass() + { + TestListResolver resolver = new TestListResolver( "my.package.MyTest" ); + assertFalse( resolver.shouldRun( "my/package/AnotherTest.class", null ) ); + assertTrue( resolver.shouldRun( "my/package/MyTest.class", null ) ); + } }