}
public RunResult invoke( Object forkTestSet )
throws TestSetFailedException
{
final ReporterFactory reporterFactory = providerParameters.getReporterFactory();
final ConsoleLogger consoleLogger = providerParameters.getConsoleLogger();
Filter filter = jUnit48Reflector.isJUnit48Available() ? createJUnit48Filter() : null;
if ( testsToRun == null )
{
if ( forkTestSet instanceof TestsToRun )
{
testsToRun = (TestsToRun) forkTestSet;
}
else if ( forkTestSet instanceof Class )
{
Class theClass = (Class) forkTestSet;
testsToRun = TestsToRun.fromClass( theClass );
}
else
{
testsToRun = scanClassPath();
}
}
customRunListeners.add( 0, getRunListener( reporterFactory, consoleLogger ) );
// Add test failure listener
JUnitTestFailureListener testFailureListener = new JUnitTestFailureListener();
customRunListeners.add( 0, testFailureListener );
JUnitCoreWrapper.execute( testsToRun, jUnitCoreParameters, customRunListeners, filter );
// Rerun failing tests if rerunFailingTestsCount is larger than 0
if ( rerunFailingTestsCount > 0 )
{
for ( int i = 0; i < rerunFailingTestsCount && !testFailureListener.getAllFailures().isEmpty(); i++ )
{
Map<Class<?>, Set<String>> failingTests =
JUnit4ProviderUtil.generateFailingTests( testFailureListener.getAllFailures(), testsToRun );
testFailureListener.reset();
final FilterFactory filterFactory = new FilterFactory( testClassLoader );
Filter failingMethodsFilter = filterFactory.createFailingMethodFilter( failingTests );
JUnitCoreWrapper.execute( testsToRun, jUnitCoreParameters, customRunListeners,
filterFactory.and( filter, failingMethodsFilter ) );
}
}
return reporterFactory.close();
}