if (!okToProceed) {
//
// Not okToProceed. Test is being skipped
//
ITestResult testResult = new TestResult(testClass, null /* instance */,
testMethod,
null /* cause */,
start,
System.currentTimeMillis());
String missingGroup = testMethod.getMissingGroup();
if (missingGroup != null) {
testResult.setThrowable(new Throwable("Method " + testMethod
+ " depends on nonexistent group \"" + missingGroup + "\""));
}
testResult.setStatus(ITestResult.SKIP);
result.add(testResult);
m_notifier.addSkippedTest(testMethod, testResult);
runTestListeners(testResult);
return result;
}
//
// If threadPoolSize specified, run this method in its own pool thread.
//
if (testMethod.getThreadPoolSize() > 1 && testMethod.getInvocationCount() > 1) {
return invokePooledTestMethods(testMethod, allTestMethods, suite,
parameters, groupMethods, testContext);
}
//
// No threads, regular invocation
//
else {
ITestNGMethod[] beforeMethods = filterMethods(testClass, testClass.getBeforeTestMethods());
ITestNGMethod[] afterMethods = filterMethods(testClass, testClass.getAfterTestMethods());
Map<String, String> allParameterNames = Maps.newHashMap();
ParameterBag bag = createParameters(testClass, testMethod,
parameters, allParameterNames, null, suite, testContext, instances[0],
null);
if (bag.hasErrors()) {
failureCount = handleInvocationResults(testMethod,
bag.errorResults, null, failureCount, expectedExceptionHolder, true,
true /* collect results */);
ITestResult tr = registerSkippedTestResult(testMethod, instances[0], start,
bag.errorResults.get(0).getThrowable());
result.add(tr);
continue;
}
Iterator<Object[]> allParameterValues = bag.parameterHolder.parameters;
int parametersIndex = 0;
try {
List<TestMethodWithDataProviderMethodWorker> workers = Lists.newArrayList();
if (bag.parameterHolder.origin == ParameterOrigin.ORIGIN_DATA_PROVIDER &&
bag.parameterHolder.dataProviderHolder.annotation.isParallel()) {
while (allParameterValues.hasNext()) {
Object[] parameterValues = injectParameters(allParameterValues.next(),
testMethod.getMethod(), testContext, null /* test result */);
TestMethodWithDataProviderMethodWorker w =
new TestMethodWithDataProviderMethodWorker(this,
testMethod, parametersIndex,
parameterValues, instances, suite, parameters, testClass,
beforeMethods, afterMethods, groupMethods,
expectedExceptionHolder, testContext, m_skipFailedInvocationCounts,
invocationCount, failureCount, m_notifier);
workers.add(w);
// testng387: increment the param index in the bag.
parametersIndex++;
}
PoolService ps = PoolService.getInstance();
List<ITestResult> r = ps.submitTasksAndWait(testMethod, workers);
result.addAll(r);
} else {
while (allParameterValues.hasNext()) {
Object[] parameterValues = injectParameters(allParameterValues.next(),
testMethod.getMethod(), testContext, null /* test result */);
List<ITestResult> tmpResults = Lists.newArrayList();
try {
tmpResults.addAll(invokeTestMethod(instances,
testMethod,
parameterValues,
parametersIndex,
suite,
parameters,
testClass,
beforeMethods,
afterMethods,
groupMethods));
}
finally {
List<Object> failedInstances = Lists.newArrayList();
failureCount = handleInvocationResults(testMethod, tmpResults,
failedInstances, failureCount, expectedExceptionHolder, true,
false /* don't collect results */);
if (failedInstances.isEmpty()) {
result.addAll(tmpResults);
} else {
for (int i = 0; i < failedInstances.size(); i++) {
List<ITestResult> retryResults = Lists.newArrayList();
failureCount =
retryFailed(failedInstances.toArray(),
i, testMethod, suite, testClass, beforeMethods,
afterMethods, groupMethods, retryResults,
failureCount, expectedExceptionHolder,
testContext, parameters, parametersIndex);
result.addAll(retryResults);
}
}
//
// If we have a failure, skip all the
// other invocationCounts
//
if (failureCount > 0
&& (m_skipFailedInvocationCounts
|| testMethod.skipFailedInvocations())) {
while (invocationCount-- > 0) {
result.add(registerSkippedTestResult(testMethod, instances[0], start, null));
}
break;
}
}// end finally
parametersIndex++;
}
}
}
catch (Throwable cause) {
ITestResult r =
new TestResult(testMethod.getTestClass(),
instances[0],
testMethod,
cause,
start,
System.currentTimeMillis());
r.setStatus(TestResult.FAILURE);
result.add(r);
runTestListeners(r);
m_notifier.addFailedTest(testMethod, r);
} // catch
}