use of org.testng.ITestResult in project ats-framework by Axway.
the class AtsTestngTestListener method dependencyError.
private boolean dependencyError(ITestResult testResult) {
String[] dependentMethods = testResult.getMethod().getMethodsDependedUpon();
List<ITestResult> failedTests = getFailedTests();
for (String dependentMethod : dependentMethods) {
for (ITestResult failedTestResult : failedTests) {
String failedMethodName = new StringBuilder().append(failedTestResult.getTestClass().getName()).append(".").append(failedTestResult.getName()).toString();
if (failedMethodName.equals(dependentMethod)) {
logger.error("Dependent method '" + dependentMethod + "' failed!", failedTestResult.getThrowable());
return true;
}
}
}
return false;
}
use of org.testng.ITestResult in project sonar-java by SonarSource.
the class TestNGListenerTest method mockTestResult.
private ITestResult mockTestResult() {
ITestResult testResult = mock(ITestResult.class);
ITestClass testClass = mock(ITestClass.class);
when(testResult.getTestClass()).thenReturn(testClass);
ITestNGMethod testMethod = mock(ITestNGMethod.class);
when(testResult.getMethod()).thenReturn(testMethod);
when(testClass.getName()).thenReturn("class");
when(testMethod.getMethodName()).thenReturn("method");
return testResult;
}
use of org.testng.ITestResult in project carina by qaprosoft.
the class AbstractTestListener method removeIncorrectlyFailedTests.
/**
* When the test is restarted this method cleans fail statistics in test context.
*/
private void removeIncorrectlyFailedTests(ITestContext context) {
// List of test results which we will delete later
List<ITestResult> testsToBeRemoved = new ArrayList<>();
// collect all id's from passed test
Set<Long> passedTestIds = new HashSet<>();
for (ITestResult passedTest : context.getPassedTests().getAllResults()) {
// adding passed test
long passedTestId = getMethodId(passedTest);
// LOGGER.debug("Adding passedTest info: " + passedTestId + "; " + passedTest.getName());
passedTestIds.add(passedTestId);
}
// LOGGER.debug("---------------- ANALYZE FAILED RESULTS FOR DUPLICATES -----------------------");
Set<Long> failedTestIds = new HashSet<>();
for (ITestResult failedTest : context.getFailedTests().getAllResults()) {
// id = class + method + dataprovider
long failedTestId = getMethodId(failedTest);
// or delete this failed test if there is at least one passed version
if (failedTestIds.contains(failedTestId) || passedTestIds.contains(failedTestId)) {
// LOGGER.debug("Test to be removed from context: " + failedTestId + "; " + failedTest.getName());
testsToBeRemoved.add(failedTest);
} else {
// LOGGER.debug("Test to mark as failed: " + failedTestId + "; " + failedTest.getName());
failedTestIds.add(failedTestId);
}
}
// finally delete all tests that are marked for removal
for (Iterator<ITestResult> iterator = context.getFailedTests().getAllResults().iterator(); iterator.hasNext(); ) {
ITestResult testResult = iterator.next();
if (testsToBeRemoved.contains(testResult)) {
// LOGGER.debug("Removing test from context: " + testResult.getName());
iterator.remove();
}
}
}
use of org.testng.ITestResult in project carina by qaprosoft.
the class AbstractTestListener method skipItem.
private String skipItem(ITestResult result, Messager messager) {
String test = TestNamingUtil.getCanonicalTestName(result);
String errorMessage = getFailureReason(result);
if (errorMessage.isEmpty()) {
// identify is it due to the dependent failure or exception in before suite/class/method
String[] methods = result.getMethod().getMethodsDependedUpon();
// find if any parent method failed/skipped
boolean dependentMethod = false;
String dependentMethodName = "";
for (ITestResult failedTest : result.getTestContext().getFailedTests().getAllResults()) {
for (int i = 0; i < methods.length; i++) {
if (methods[i].contains(failedTest.getName())) {
dependentMethodName = failedTest.getName();
dependentMethod = true;
break;
}
}
}
for (ITestResult skippedTest : result.getTestContext().getSkippedTests().getAllResults()) {
for (int i = 0; i < methods.length; i++) {
if (methods[i].contains(skippedTest.getName())) {
dependentMethodName = skippedTest.getName();
dependentMethod = true;
break;
}
}
}
if (dependentMethod) {
errorMessage = "Test skipped due to the dependency from: " + dependentMethodName;
} else {
// Try to find error details from last configuration failure in this thread
TestResultItem resultItem = getConfigFailure();
if (resultItem != null) {
errorMessage = resultItem.getFailReason();
}
}
}
String deviceName = getDeviceName();
messager.info(deviceName, test, DateUtils.now(), errorMessage);
EmailReportItemCollector.push(createTestResult(result, TestResultType.SKIP, errorMessage, result.getMethod().getDescription()));
result.getTestContext().removeAttribute(SpecialKeywords.TEST_FAILURE_MESSAGE);
return errorMessage;
}
use of org.testng.ITestResult in project carina by qaprosoft.
the class AbstractTestListener method getFailureReason.
protected String getFailureReason(ITestResult result) {
String errorMessage = "";
String message = "";
if (result.getThrowable() != null) {
Throwable thr = result.getThrowable();
errorMessage = getFullStackTrace(thr);
message = thr.getMessage();
result.getTestContext().setAttribute(SpecialKeywords.TEST_FAILURE_MESSAGE, message);
}
// handle in case of failed config (exclusion of expected skip)
if (errorMessage.isEmpty()) {
String methodName;
Collection<ITestResult> results = result.getTestContext().getSkippedConfigurations().getAllResults();
for (ITestResult resultItem : results) {
methodName = resultItem.getMethod().getMethodName();
if (methodName.equals(SpecialKeywords.BEFORE_TEST_METHOD)) {
errorMessage = getFullStackTrace(resultItem.getThrowable());
}
}
}
return errorMessage;
}
Aggregations