Java Code Examples for org.testng.ITestResult#setStatus()

The following examples show how to use org.testng.ITestResult#setStatus() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QuickPerfTestNGListener.java    From quickperf with Apache License 2.0 7 votes vote down vote up
private void executeTestMethodInNewJvmAndRecordPerformance(ITestResult testResult, TestExecutionContext testExecutionContext) {

        Object[] args = new Object[0];
        Method method = extractTestMethod(testResult);

        performanceRecording.start(testExecutionContext);

        try {
            Object target = testResult.getInstance();
            //directly invoke the method to lower the interaction between JUnit, other extensions and QuickPerf.
            method.invoke(target, args);
        } catch (Throwable throwable) {
            testResult.setThrowable(throwable);
            testResult.setStatus(ITestResult.FAILURE);
        } finally {
            performanceRecording.stop(testExecutionContext);
        }

    }
 
Example 2
Source File: QAFTestNGListener.java    From qaf with MIT License 7 votes vote down vote up
protected void setSkip(ITestResult tr, ITestContext context) {

		if (getBundle().getInt("testng.version", 6) > 5) {

			// Fix for testNG 6
			if ((null != context.getFailedTests())) {
				if (((null != context.getFailedTests().getResults(tr.getMethod())))
						&& (context.getFailedTests().getResults(tr.getMethod())
								.size() > 1)) {
					context.getFailedTests().getResults(tr.getMethod()).remove(tr);
				} else {
					context.getFailedTests().removeResult(tr.getMethod());
				}
			}
			tr.setStatus(ITestResult.SKIP);
			if (null != context.getSkippedTests()) {
				context.getSkippedTests().addResult(tr, tr.getMethod());
			}
		} else {
			tr.setStatus(ITestResult.SKIP);
		}
	}
 
Example 3
Source File: AtsTestngListener.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
private void endTestcaseWithSuccessStatus( ITestResult testResult ) {

        sendTestEndEventToAgents();
        boolean shouldTestFail = TestcaseStateEventsDispacher.getInstance().hasAnyQueueFailed();
        if (shouldTestFail) {
            logger.warn("At least one queue in test failed");
            testResult.setStatus(ITestResult.FAILURE);
            endTestcaseWithFailureStatus(testResult);
            return;
        }
        logger.info(MSG__TEST_PASSED);

        try {

            currentTestcaseName = null;
            lastTestcaseResult = TestCaseResult.PASSED.toInt();
            // end test case
            logger.endTestcase(TestCaseResult.PASSED);
        } catch (Exception e) {
            logger.fatal("UNEXPECTED EXCEPTION IN AtsTestngListener@endTestcaseWithSuccessStatus", e);
        }

    }
 
Example 4
Source File: QAFTestNGListener.java    From qaf with MIT License 6 votes vote down vote up
protected void setFailure(ITestResult tr, ITestContext context) {

		if (getBundle().getInt("testng.version", 6) > 5) {
			// Fix for testNG 6
			// IResultMap resultMap = context.getPassedTests();
			// resultMap.
			if ((null != context.getPassedTests())) {

				if (context.getPassedTests().getResults(tr.getMethod()).size() > 1) {
					context.getPassedTests().removeResult(tr);
				} else {
					context.getPassedTests().removeResult(tr.getMethod());
				} // removeResult(tr.getMethod());
			}
			tr.setStatus(ITestResult.FAILURE);
			if (null != context.getFailedTests()) {
				context.getFailedTests().addResult(tr, tr.getMethod());
			}
		} else {
			tr.setStatus(ITestResult.FAILURE);

		}
	}
 
Example 5
Source File: ReportManager.java    From difido-reports with Apache License 2.0 6 votes vote down vote up
void onTestSuccess(ITestResult result) {
	if (!failureMessages.isEmpty()) {
		StringBuilder sb = new StringBuilder();
		boolean first = true;
		for (String message : failureMessages) {
			if (first) {
				first = false;
			} else {
				sb.append(",\n");
			}
			sb.append(message);
		}
		result.setStatus(2);
		result.setThrowable(new AssertionError(sb.toString()));
		onTestFailure(result);
		return;
	}

	for (Reporter reporter : reporters) {
		reporter.onTestSuccess(result);
	}

}
 
Example 6
Source File: SingleConsumerQueueTest.java    From caffeine with Apache License 2.0 6 votes vote down vote up
@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
  try {
    if (testResult.isSuccess()) {
      for (Object param : testResult.getParameters()) {
        if (param instanceof SingleConsumerQueue<?>) {
          assertThat((SingleConsumerQueue<?>) param, is(validate()));
        }
      }
    }
  } catch (AssertionError caught) {
    testResult.setStatus(ITestResult.FAILURE);
    testResult.setThrowable(caught);
  } finally {
    cleanUp(testResult);
  }
}
 
Example 7
Source File: CacheValidationListener.java    From caffeine with Apache License 2.0 6 votes vote down vote up
@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
  try {
    if (testResult.isSuccess()) {
      validate(testResult);
    } else {
      if (!detailedParams.get()) {
        detailedParams.set(true);
      }
      testResult.setThrowable(new AssertionError(getTestName(method), testResult.getThrowable()));
    }
  } catch (Throwable caught) {
    testResult.setStatus(ITestResult.FAILURE);
    testResult.setThrowable(new AssertionError(getTestName(method), caught));
  } finally {
    cleanUp(testResult);
  }
}
 
Example 8
Source File: BaseClassForTests.java    From curator with Apache License 2.0 6 votes vote down vote up
private boolean retry(ITestResult result)
{
    if ( result.isSuccess() || isRetrying.get() )
    {
        isRetrying.set(false);
        return false;
    }

    result.setStatus(ITestResult.SKIP);
    if ( result.getThrowable() != null )
    {
        log.error("Retrying 1 time", result.getThrowable());
    }
    else
    {
        log.error("Retrying 1 time");
    }
    isRetrying.set(true);
    return true;
}
 
Example 9
Source File: QuickPerfTestNGListener.java    From quickperf with Apache License 2.0 5 votes vote down vote up
@Override
public void run(IHookCallBack hookCallBack, ITestResult testResult) {

    TestExecutionContext testExecutionContext = buildTestExecutionContext(testResult);

    if(testExecutionContext.isQuickPerfDisabled()) {
        hookCallBack.runTestMethod(testResult);
        return;
    }

    if(SystemProperties.TEST_CODE_EXECUTING_IN_NEW_JVM.evaluate()) {
        executeTestMethodInNewJvmAndRecordPerformance(testResult, testExecutionContext);
        return;
    }

    JvmOrTestIssue jvmOrTestIssue =
            executeTestMethodAndRecordPerformance(hookCallBack, testResult, testExecutionContext);

    SetOfAnnotationConfigs testAnnotationConfigs = quickPerfConfigs.getTestAnnotationConfigs();
    Collection<PerfIssuesToFormat> groupOfPerfIssuesToFormat = perfIssuesEvaluator.evaluatePerfIssuesIfNoJvmIssue(testAnnotationConfigs
                                                                                                                , testExecutionContext
                                                                                                                , jvmOrTestIssue);

    testExecutionContext.cleanResources();

    try {
        quickPerfReporter.report(jvmOrTestIssue, groupOfPerfIssuesToFormat, testExecutionContext);
    } catch (Throwable throwable) {
        testResult.setThrowable(throwable);
        testResult.setStatus(ITestResult.FAILURE);
    }

}
 
Example 10
Source File: MobileTest.java    From functional-tests-core with Apache License 2.0 5 votes vote down vote up
/**
 * Get memory usage and log it.
 * Assert memory usage is less than memoryMaxUsageLimit (if memoryMaxUsageLimit is specified).
 *
 * @param result
 */
protected void checkMemoryPerformance(ITestResult result) {
    if (this.settings.platform == PlatformType.Android) {
        int usedMemory = this.device.getMemUsage(this.settings.packageId);
        if (usedMemory > -1) {
            LOGGER.info("Used memory: " + usedMemory);

            int currentMaxMem = this.context.device.getAndroidDevice().getMaxUsedMemory();
            if (currentMaxMem < usedMemory) {
                currentMaxMem = usedMemory;
                this.context.device.getAndroidDevice().setMaxUsedMemory(currentMaxMem);
                LOGGER.debug("Maximum used memory: " + currentMaxMem);
            }

            if (this.settings.android.memoryMaxUsageLimit > 0) {
                LOGGER.info("Expected max memory usage: " + this.settings.android.memoryMaxUsageLimit);
                if (this.settings.android.memoryMaxUsageLimit < usedMemory) {
                    LOGGER.error("=== Memory leak appears after test " + result.getName() + " ====");
                    Assert.assertTrue(false, "Used memory of " + usedMemory + " is more than expected " + this.settings.android.memoryMaxUsageLimit + " !!!");
                    result.setStatus(ITestResult.FAILURE);
                }
            }
        } else {
            LOGGER.error("Failed to get memory usage stats.");
        }
    } else {
        this.log.debug("Check performance not implemented for iOS.");
    }
}
 
Example 11
Source File: IConfigurationListenerCustom.java    From functional-tests-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onConfigurationFailure(ITestResult iTestResult) {
    if (!iTestResult.getMethod().isTest() && !iTestResult.isSuccess()) {
        loggerBase.debug(iTestResult.getMethod().getMethodName());
        loggerBase.debug(iTestResult.getTestName());
        iTestResult.setStatus(ITestResult.FAILURE);
    }

    System.out.println("on configuration failure");

}
 
Example 12
Source File: IConfigurationListenerCustom.java    From functional-tests-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onConfigurationSkip(ITestResult iTestResult) {
    if (!iTestResult.getMethod().isTest() && !iTestResult.isSuccess()) {
        loggerBase.debug(iTestResult.getMethod().getMethodName());
        loggerBase.debug(iTestResult.getTestName());
        iTestResult.setStatus(ITestResult.FAILURE);
    }

    System.out.println("on configuration skip");

}
 
Example 13
Source File: AbstractTest.java    From concurrentlinkedhashmap with Apache License 2.0 5 votes vote down vote up
@AfterMethod(alwaysRun = true)
public void validateIfSuccessful(ITestResult result) {
  try {
    if (result.isSuccess()) {
      for (Object param : result.getParameters()) {
        validate(param);
      }
    }
  } catch (AssertionError caught) {
    result.setStatus(ITestResult.FAILURE);
    result.setThrowable(caught);
  }
  initMocks(this);
}
 
Example 14
Source File: TestMethodListener.java    From oxd with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) {
    Method method = iTestResult.getMethod().getConstructorOrMethod().getMethod();
    if (method == null) {
        return;
    }
    if (method.isAnnotationPresent(ProtectionAccessTokenRequired.class)) {
        if (!Tester.isTokenProtectionEnabled()) {
            iTestResult.setStatus(ITestResult.SKIP);
            throw new SkipException("Skipping the test as protection access token is not enabled. Ignore the exception.");
        }
    }
}
 
Example 15
Source File: Listener.java    From elasticsearch-gatherer with Apache License 2.0 4 votes vote down vote up
@Override
public void onTestSkipped(ITestResult result) {
    logger.info("skipped test {}", result.getMethod().getMethodName());
    result.setStatus(ITestResult.FAILURE);
}
 
Example 16
Source File: AbstractTestListener.java    From carina with Apache License 2.0 4 votes vote down vote up
@Override
public void onTestSkipped(ITestResult result) {
    LOGGER.debug("AbstractTestListener->onTestSkipped");
    // handle Zafira already passed exception for re-run and do nothing. Return should be enough
    if (result.getThrowable() != null && result.getThrowable().getMessage() != null
            && result.getThrowable().getMessage().startsWith(SpecialKeywords.ALREADY_PASSED)) {
        // [VD] it is prohibited to release TestInfoByThread in this place.!
        skipTestItem(result, Messager.TEST_SKIPPED_AS_ALREADY_PASSED);
        // [VD] no need to reset as TestNG doesn't launch retryAnalyzer so we don't increment it on ALREADY_PASSED skip exception
        return;
    }
    
    // handle AbstractTest->SkipExecution
    if (result.getThrowable() != null && result.getThrowable().getMessage() != null
            && result.getThrowable().getMessage().startsWith(SpecialKeywords.SKIP_EXECUTION)) {
        // [VD] it is prohibited to release TestInfoByThread in this place.!
        return;
    }
    
    // handle Zafira already failed by known bug exception for re-run and do nothing
    if (result.getThrowable() != null && result.getThrowable().getMessage() != null
            && result.getThrowable().getMessage().startsWith(SpecialKeywords.ALREADY_FAILED_BY_KNOWN_BUG)) {
        skipTestItem(result, Messager.TEST_SKIPPED_AS_ALREADY_FAILED_BY_BUG);
        return;
    }
    
    RetryAnalyzer retryAnalyzer = getRetryAnalyzer(result);
    int count = retryAnalyzer != null ? count = retryAnalyzer.getRunCount() : 0;
    
    int maxCount = RetryAnalyzer.getMaxRetryCountForTest();
    LOGGER.debug("count: " + count + "; maxCount:" + maxCount);
    
    if (count > 0 && retryAnalyzer == null) {
        LOGGER.error("retry_count will be ignored as RetryAnalyzer is not declared for "
                + result.getMethod().getMethodName());
    } else if (count > 0 && count <= maxCount && !Jira.isRetryDisabled(result)) {
        failRetryItem(result, Messager.RETRY_FAILED, count, maxCount + 1);
        result.setStatus(2);
        afterTest(result);
        super.onTestFailure(result);
    } else {
        skipItem(result, Messager.TEST_SKIPPED);
        afterTest(result);
        super.onTestSkipped(result);
        
        if (retryAnalyzer != null) {
            // resetCounter for current thread needed to support correctly data-provider reruns (multi-threading as well)
            retryAnalyzer.resetCounter();
        }
    }
}