Repository: maven-surefire Updated Branches: refs/heads/master 6e5fb5695 -> d4aa9b7ac
[SUREFIRE-1138] Enabling reuseForks runs all tests in series on just one fork Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/d4aa9b7a Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/d4aa9b7a Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/d4aa9b7a Branch: refs/heads/master Commit: d4aa9b7ac3aa36a229170ed8fb2993df5440e561 Parents: 6e5fb56 Author: Tibor17 <tibo...@lycos.com> Authored: Sat Jul 4 11:04:18 2015 +0200 Committer: Tibor17 <tibo...@lycos.com> Committed: Sat Jul 4 11:04:18 2015 +0200 ---------------------------------------------------------------------- .../common/junit4/JUnit4ProviderUtil.java | 3 +- .../surefire/common/junit4/JUnit4Reflector.java | 38 ++++++++++++++++++-- .../common/junit4/JUnit4RunListener.java | 4 +-- .../common/junit4/JUnit4Reflector40Test.java | 3 +- .../maven/surefire/junit4/JUnit4Provider.java | 7 +++- .../junitcore/JUnit4Reflector481Test.java | 9 ++--- 6 files changed, 49 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d4aa9b7a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4ProviderUtil.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4ProviderUtil.java b/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4ProviderUtil.java index 05988b7..0809b08 100644 --- a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4ProviderUtil.java +++ b/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4ProviderUtil.java @@ -108,8 +108,7 @@ public final class JUnit4ProviderUtil public static Description createSuiteDescription( Collection<Class<?>> classes ) { - JUnit4Reflector reflector = new JUnit4Reflector(); - return reflector.createRequest( classes.toArray( new Class[classes.size()] ) ) + return JUnit4Reflector.createRequest( classes.toArray( new Class[classes.size()] ) ) .getRunner() .getDescription(); } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d4aa9b7a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4Reflector.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4Reflector.java b/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4Reflector.java index 70ae62a..35dc888 100644 --- a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4Reflector.java +++ b/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4Reflector.java @@ -19,6 +19,7 @@ package org.apache.maven.surefire.common.junit4; * under the License. */ +import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import org.apache.maven.surefire.util.ReflectionUtils; @@ -38,7 +39,12 @@ public final class JUnit4Reflector private static final Class[] IGNORE_PARAMS = new Class[]{ Ignore.class }; - public Ignore getAnnotatedIgnore( Description description ) + private JUnit4Reflector() + { + throw new IllegalStateException( "not instantiable constructor" ); + } + + public static Ignore getAnnotatedIgnore( Description description ) { Method getAnnotation = ReflectionUtils.tryGetMethod( description.getClass(), "getAnnotation", PARAMS ); @@ -50,13 +56,13 @@ public final class JUnit4Reflector return (Ignore) ReflectionUtils.invokeMethodWithArray( description, getAnnotation, IGNORE_PARAMS ); } - public String getAnnotatedIgnoreValue( Description description ) + public static String getAnnotatedIgnoreValue( Description description ) { final Ignore ignore = getAnnotatedIgnore( description ); return ignore != null ? ignore.value() : null; } - public Request createRequest( Class<?>... classes ) + public static Request createRequest( Class<?>... classes ) { try { @@ -77,4 +83,30 @@ public final class JUnit4Reflector throw new SurefireReflectionException( e ); } } + + public static Description createDescription( String description ) + { + try + { + return Description.createSuiteDescription( description ); + } + catch ( NoSuchMethodError e ) + { + try + { + return (Description) Description.class.getDeclaredMethod( "createSuiteDescription", + String.class, Annotation[].class ) + .invoke( null, description, new Annotation[0] ); + } + catch ( InvocationTargetException e1 ) + { + throw new SurefireReflectionException( e1.getCause() ); + } + catch ( Exception e1 ) + { + // probably JUnit 5.x + throw new SurefireReflectionException( e1 ); + } + } + } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d4aa9b7a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4RunListener.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4RunListener.java b/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4RunListener.java index ba5b637..276f3d4 100644 --- a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4RunListener.java +++ b/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4RunListener.java @@ -52,8 +52,6 @@ public class JUnit4RunListener */ private final ThreadLocal<Boolean> failureFlag = new InheritableThreadLocal<Boolean>(); - private final JUnit4Reflector jUnit4Reflector = new JUnit4Reflector(); - /** * Constructor. * @@ -74,7 +72,7 @@ public class JUnit4RunListener public void testIgnored( Description description ) throws Exception { - final String reason = jUnit4Reflector.getAnnotatedIgnoreValue( description ); + final String reason = JUnit4Reflector.getAnnotatedIgnoreValue( description ); final SimpleReportEntry report = SimpleReportEntry.ignored( getClassName( description ), description.getDisplayName(), reason ); reporter.testSkipped( report ); http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d4aa9b7a/surefire-providers/common-junit4/src/test/java/org/apache/maven/surefire/common/junit4/JUnit4Reflector40Test.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-junit4/src/test/java/org/apache/maven/surefire/common/junit4/JUnit4Reflector40Test.java b/surefire-providers/common-junit4/src/test/java/org/apache/maven/surefire/common/junit4/JUnit4Reflector40Test.java index 2444065..979adb8 100644 --- a/surefire-providers/common-junit4/src/test/java/org/apache/maven/surefire/common/junit4/JUnit4Reflector40Test.java +++ b/surefire-providers/common-junit4/src/test/java/org/apache/maven/surefire/common/junit4/JUnit4Reflector40Test.java @@ -33,9 +33,8 @@ public class JUnit4Reflector40Test @Test public void testGetAnnotatedIgnore() { - JUnit4Reflector reflector = new JUnit4Reflector(); Description desc = Description.createTestDescription( IgnoreWithDescription.class, "testSomething2" ); - Ignore annotatedIgnore = reflector.getAnnotatedIgnore( desc ); + Ignore annotatedIgnore = JUnit4Reflector.getAnnotatedIgnore( desc ); Assert.assertNull( annotatedIgnore ); } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d4aa9b7a/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java b/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java index 351e9c1..45b907d 100644 --- a/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java +++ b/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java @@ -28,6 +28,7 @@ import java.util.Set; import org.apache.maven.surefire.common.junit4.ClassMethod; import org.apache.maven.surefire.common.junit4.JUnit4ProviderUtil; +import org.apache.maven.surefire.common.junit4.JUnit4Reflector; import org.apache.maven.surefire.common.junit4.JUnit4RunListener; import org.apache.maven.surefire.common.junit4.JUnit4RunListenerFactory; import org.apache.maven.surefire.common.junit4.JUnit4TestChecker; @@ -60,6 +61,8 @@ import org.junit.runner.notification.RunNotifier; public class JUnit4Provider extends AbstractProvider { + private static final String UNDETERMINED_TESTS_DESCRIPTION = "cannot determine test in forked JVM with surefire"; + private final ClassLoader testClassLoader; private final List<org.junit.runner.notification.RunListener> customRunListeners; @@ -123,7 +126,9 @@ public class JUnit4Provider Result result = new Result(); RunNotifier runNotifier = getRunNotifier( jUnit4TestSetReporter, result, customRunListeners ); - runNotifier.fireTestRunStarted( createTestsDescription() ); + runNotifier.fireTestRunStarted( testsToRun.allowEagerReading() + ? createTestsDescription() + : JUnit4Reflector.createDescription( UNDETERMINED_TESTS_DESCRIPTION ) ); for ( Class aTestsToRun : testsToRun ) { http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d4aa9b7a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnit4Reflector481Test.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnit4Reflector481Test.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnit4Reflector481Test.java index 413ef03..7d4b102 100644 --- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnit4Reflector481Test.java +++ b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnit4Reflector481Test.java @@ -24,11 +24,12 @@ import java.lang.reflect.Method; import org.apache.maven.surefire.common.junit4.JUnit4Reflector; import org.apache.maven.surefire.util.ReflectionUtils; -import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.Description; +import static org.junit.Assert.*; + /** * Reflector Test with junit 4.8.1 * @@ -41,14 +42,14 @@ public class JUnit4Reflector481Test @Test public void testGetAnnotatedIgnore() { - JUnit4Reflector reflector = new JUnit4Reflector(); final Method testSomething2 = ReflectionUtils.getMethod( IgnoreWithDescription.class, "testSomething2", EMPTY_CLASS_ARRAY ); final Annotation[] annotations = testSomething2.getAnnotations(); Description desc = Description.createTestDescription( IgnoreWithDescription.class, "testSomething2", annotations ); - Ignore annotatedIgnore = reflector.getAnnotatedIgnore( desc ); - Assert.assertEquals( reason, annotatedIgnore.value() ); + Ignore annotatedIgnore = JUnit4Reflector.getAnnotatedIgnore( desc ); + assertNotNull( annotatedIgnore ); + assertEquals( reason, annotatedIgnore.value() ); } private static final String reason = "Ignorance is bliss";