Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SUREFIRE-839] Tests not matching categories would fail build #12

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ public void classWithoutCategory()
{
unpack( "junit48-categories" ).setJUnitVersion( "4.11" ).executeTest().verifyErrorFree( 2 );
}

@Test
public void classWithoutCategoryForked()
{
unpack( "junit48-categories" ).setJUnitVersion( "4.11" ).forkOncePerThread().threadCount(2).executeTest().verifyErrorFree( 2 );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,6 @@ public Iterator getSuites()
return testsToRun.iterator();
}

private boolean containsSomethingRunnable( TestsToRun testsToRun, Filter filter )
{
if ( filter == null )
{
return true;
}
for ( Class o : testsToRun.getLocatedClasses() )
{
if ( canRunClass( filter, o ) )
{
return true;
}
}
return false;
}

public RunResult invoke( Object forkTestSet )
throws TestSetFailedException, ReporterException
{
Expand Down Expand Up @@ -147,24 +131,20 @@ else if ( forkTestSet instanceof Class )
}
}

if ( containsSomethingRunnable( testsToRun, filter ) )
{

final Map<String, TestSet> testSetMap = new ConcurrentHashMap<String, TestSet>();
final Map<String, TestSet> testSetMap = new ConcurrentHashMap<String, TestSet>();

RunListener listener = ConcurrentReporterManager.createInstance( testSetMap, reporterFactory,
jUnitCoreParameters.isParallelClasses(),
jUnitCoreParameters.isParallelBoth(),
consoleLogger );
RunListener listener = ConcurrentReporterManager.createInstance( testSetMap, reporterFactory,
jUnitCoreParameters.isParallelClasses(),
jUnitCoreParameters.isParallelBoth(),
consoleLogger );

ConsoleOutputCapture.startCapture( (ConsoleOutputReceiver) listener );
ConsoleOutputCapture.startCapture( (ConsoleOutputReceiver) listener );

org.junit.runner.notification.RunListener jUnit4RunListener =
new JUnitCoreRunListener( listener, testSetMap );
customRunListeners.add( 0, jUnit4RunListener );
org.junit.runner.notification.RunListener jUnit4RunListener =
new JUnitCoreRunListener( listener, testSetMap );
customRunListeners.add( 0, jUnit4RunListener );

JUnitCoreWrapper.execute( testsToRun, jUnitCoreParameters, customRunListeners, filter );
}
JUnitCoreWrapper.execute( testsToRun, jUnitCoreParameters, customRunListeners, filter );
return reporterFactory.close();
}

Expand Down Expand Up @@ -192,14 +172,10 @@ private TestsToRun getSuitesAsList( Filter filter )

private boolean canRunClass( Filter filter, Class<?> clazz )
{
boolean isCategoryAnnotatedClass = jUnit48Reflector.isCategoryAnnotationPresent( clazz );
Description d = Description.createSuiteDescription( clazz );
final Description d = Description.createSuiteDescription( clazz );
if ( filter.shouldRun( d ) )
{
return true;
}
else
{
// if the class-level check passes, we need to check if any methods are left to run
for ( Method method : clazz.getMethods() )
{
final Description testDescription =
Expand All @@ -210,6 +186,7 @@ private boolean canRunClass( Filter filter, Class<?> clazz )
}
}
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* under the License.
*/

import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutionException;
import org.apache.maven.surefire.common.junit4.JUnit4RunListener;
Expand Down Expand Up @@ -53,14 +54,19 @@ public static void execute( TestsToRun testsToRun, JUnitCoreParameters jUnitCore

try
{
Request req = Request.classes( computer, testsToRun.getLocatedClasses() );
if ( filter != null )
// in order to support LazyTestsToRun, the iterator must be used
Iterator classIter = testsToRun.iterator();
while (classIter.hasNext())
{
req = req.filterWith( filter );
}
Request req = Request.classes( computer, new Class[]{ (Class) classIter.next() });
if ( filter != null )
{
req = req.filterWith( filter );
}

final Result run = junitCore.run( req );
JUnit4RunListener.rethrowAnyTestMechanismFailures( run );
final Result run = junitCore.run( req );
JUnit4RunListener.rethrowAnyTestMechanismFailures( run );
}
}
finally
{
Expand Down