Author: krosenvold Date: Sat Aug 18 19:39:34 2012 New Revision: 1374642 URL: http://svn.apache.org/viewvc?rev=1374642&view=rev Log: [SUREFIRE-862] Added various tests for mismatched JUnit versions/groups.
Added IT testcases for the situations described in the issue. Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire809GroupExpressionsIT.java maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-809-groupExpr-junit48/pom.xml Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java?rev=1374642&r1=1374641&r2=1374642&view=diff ============================================================================== --- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java (original) +++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java Sat Aug 18 19:39:34 2012 @@ -601,7 +601,7 @@ public abstract class AbstractSurefireMo } boolean verifyParameters() - throws MojoFailureException + throws MojoFailureException, MojoExecutionException { setProperties( new OrderedProperties( getProperties() ) ); if ( isSkipExecution() ) @@ -633,6 +633,7 @@ public abstract class AbstractSurefireMo ensureWorkingDirectoryExists(); ensureParallelRunningCompatibility(); warnIfUselessUseSystemClassLoaderParameter(); + warnIfDefunctGroupsCombinations(); } return true; } @@ -657,10 +658,8 @@ public abstract class AbstractSurefireMo } protected List<ProviderInfo> createProviders() - throws MojoFailureException + throws MojoFailureException, MojoExecutionException { - try - { final Artifact junitDepArtifact = getJunitDepArtifact(); ProviderList wellKnownProviders = new ProviderList( new DynamicProviderInfo( null ), new TestNgProviderInfo( getTestNgArtifact() ), @@ -669,11 +668,6 @@ public abstract class AbstractSurefireMo new JUnit3ProviderInfo() ); return wellKnownProviders.resolve( getLog() ); - } - catch ( InvalidVersionSpecificationException e ) - { - throw new NestedRuntimeException( e ); - } } private Summary executeAllProviders( DefaultScanResult scanResult ) @@ -945,14 +939,7 @@ public abstract class AbstractSurefireMo new ReporterConfiguration( getReportsDirectory(), isTrimStackTrace() ); Artifact testNgArtifact; - try - { - testNgArtifact = getTestNgArtifact(); - } - catch ( InvalidVersionSpecificationException e ) - { - throw new MojoExecutionException( "Error determining the TestNG version requested: " + e.getMessage(), e ); - } + testNgArtifact = getTestNgArtifact(); DirectoryScannerParameters directoryScannerParameters = null; final boolean isTestNg = testNgArtifact != null; @@ -1185,16 +1172,16 @@ public abstract class AbstractSurefireMo } private Artifact getTestNgArtifact() - throws MojoFailureException, InvalidVersionSpecificationException + throws MojoExecutionException { Artifact artifact = getProjectArtifactMap().get( getTestNGArtifactName() ); if ( artifact != null ) { - VersionRange range = VersionRange.createFromVersionSpec( "[4.7,)" ); + VersionRange range = createVersionRange(); if ( !range.containsVersion( new DefaultArtifactVersion( artifact.getVersion() ) ) ) { - throw new MojoFailureException( + throw new MojoExecutionException( "TestNG support requires version 4.7 or above. You have declared version " + artifact.getVersion() ); } @@ -1203,6 +1190,18 @@ public abstract class AbstractSurefireMo } + private VersionRange createVersionRange() + { + try + { + return VersionRange.createFromVersionSpec( "[4.7,)" ); + } + catch ( InvalidVersionSpecificationException e ) + { + throw new RuntimeException( e ); + } + } + private Artifact getJunitArtifact() { return getProjectArtifactMap().get( getJunitArtifactName() ); @@ -1419,7 +1418,7 @@ public abstract class AbstractSurefireMo */ Classpath generateTestClasspath() throws InvalidVersionSpecificationException, MojoFailureException, ArtifactResolutionException, - ArtifactNotFoundException + ArtifactNotFoundException, MojoExecutionException { List<String> classpath = new ArrayList<String>( 2 + getProject().getArtifacts().size() ); @@ -1650,6 +1649,27 @@ public abstract class AbstractSurefireMo } } + void warnIfDefunctGroupsCombinations() + throws MojoFailureException, MojoExecutionException + { + if (isAnyGroupsSelected()){ + if (getTestNgArtifact() != null){ + return; + } + Artifact junitArtifact = getJunitArtifact(); + boolean junit47Compatible = isJunit47Compatible( junitArtifact ); + if (junit47Compatible ) + { + return; + } + if (junitArtifact != null && !junit47Compatible ){ + throw new MojoFailureException("groups/excludedGroups are specified but JUnit version on classpath" + + " is too old to support groups. Check your dependency:tree to see if your project is picking up an old junit version"); + } + throw new MojoFailureException("groups/excludedGroups require TestNG or JUunit48+ on project test classpath"); + + } + } class TestNgProviderInfo implements ProviderInfo { Modified: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire809GroupExpressionsIT.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire809GroupExpressionsIT.java?rev=1374642&r1=1374641&r2=1374642&view=diff ============================================================================== --- maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire809GroupExpressionsIT.java (original) +++ maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire809GroupExpressionsIT.java Sat Aug 18 19:39:34 2012 @@ -2,12 +2,16 @@ package org.apache.maven.surefire.its.ji import org.apache.maven.surefire.its.fixture.OutputValidator; import org.apache.maven.surefire.its.fixture.SurefireIntegrationTestCase; +import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; import org.apache.maven.surefire.its.fixture.SurefireLauncher; +import org.junit.Test; + public class Surefire809GroupExpressionsIT - extends SurefireIntegrationTestCase + extends SurefireJUnit4IntegrationTestCase { - public void testJUnitRunCategoryAB() + @Test + public void categoryAB() { OutputValidator validator = unpackJUnit().groups( "junit4.CategoryA AND junit4.CategoryB" ).executeTest(); validator.verifyErrorFreeLog(); @@ -21,6 +25,13 @@ public class Surefire809GroupExpressions validator.verifyTextInLog( "mC: 0" ); } + @Test + public void incorrectJUnitVersions() + { + unpackJUnit().setJUnitVersion( "4.5" ).groups( "junit4.CategoryA AND junit4.CategoryB" ).executeTestWithFailure(); + } + + @Test public void testJUnitRunCategoryNotC() { OutputValidator validator = unpackJUnit().groups( "!junit4.CategoryC" ).executeTest(); @@ -33,7 +44,21 @@ public class Surefire809GroupExpressions validator.verifyTextInLog( "NoCategoryTest.CatNone: 1" ); } - public void testTestNGRunCategoryAB() + @Test + public void testExcludedGroups() + { + OutputValidator validator = unpackJUnit().setExcludedGroups( "junit4.CategoryC" ).executeTest(); + validator.verifyErrorFreeLog(); + validator.assertTestSuiteResults( 5, 0, 0, 0 ); + validator.verifyTextInLog( "catA: 2" ); + validator.verifyTextInLog( "catB: 2" ); + validator.verifyTextInLog( "catC: 0" ); + validator.verifyTextInLog( "catNone: 1" ); + validator.verifyTextInLog( "NoCategoryTest.CatNone: 1" ); + } + + @Test + public void testNGRunCategoryAB() { OutputValidator validator = unpackTestNG().groups( "CategoryA AND CategoryB" ).debugLogging().executeTest(); validator.verifyErrorFreeLog(); @@ -42,7 +67,8 @@ public class Surefire809GroupExpressions validator.verifyTextInLog( "CategoryCTest.testInCategoriesAB()" ); } - public void testTestNGRunCategoryNotC() + @Test + public void testNGRunCategoryNotC() { OutputValidator validator = unpackTestNG().groups( "!CategoryC" ).debugLogging().executeTest(); validator.verifyErrorFreeLog(); Modified: maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-809-groupExpr-junit48/pom.xml URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-809-groupExpr-junit48/pom.xml?rev=1374642&r1=1374641&r2=1374642&view=diff ============================================================================== --- maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-809-groupExpr-junit48/pom.xml (original) +++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-809-groupExpr-junit48/pom.xml Sat Aug 18 19:39:34 2012 @@ -30,15 +30,14 @@ <properties> - <junitVersion>4.8.1</junitVersion> - <groups>junit4.CategoryA,junit4.CategoryB</groups> + <junit.version>4.8.1</junit.version> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> - <version>${junitVersion}</version> + <version>${junit.version}</version> <scope>test</scope> </dependency> </dependencies> @@ -57,16 +56,6 @@ <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>${surefire.version}</version> - <configuration> - <groups>${groups}</groups> - </configuration> - <dependencies> - <dependency> - <groupId>org.apache.maven.surefire</groupId> - <artifactId>surefire-junit47</artifactId> - <version>${surefire.version}</version> - </dependency> - </dependencies> </plugin> </plugins> </build>