org.testng.IResultMap Java Examples

The following examples show how to use org.testng.IResultMap. 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: Util.java    From cloudbreak with Apache License 2.0 7 votes vote down vote up
public static Measure collectMeasurements(ITestContext iTestContext) {
    if (iTestContext == null) {
        throw new IllegalArgumentException("No testng testcontext is given.");
    }
    IResultMap failed = iTestContext.getFailedTests();
    IResultMap success = iTestContext.getPassedTests();
    MeasureAll allMeasurement = new MeasureAll();
    failed.getAllResults().stream().forEach(
            getiTestResultConsumer(allMeasurement)
    );
    success.getAllResults().stream().forEach(
            getiTestResultConsumer(allMeasurement)
    );

    return allMeasurement;
}
 
Example #2
Source File: ExtentIReporterSuiteListenerAdapter.java    From extentreports-testng-adapter with Apache License 2.0 6 votes vote down vote up
private void buildTestNodes(ExtentTest suiteTest, IResultMap tests, Status status) {
    ExtentTest node;

    if (tests.size() > 0) {
        for (ITestResult result : tests.getAllResults()) {
            node = suiteTest.createNode(result.getMethod().getMethodName(), result.getMethod().getDescription());

            String groups[] = result.getMethod().getGroups();
            ExtentTestCommons.assignGroups(node, groups);

            if (result.getThrowable() != null) {
                node.log(status, result.getThrowable());
            } else {
                node.log(status, "Test " + status.toString().toLowerCase() + "ed");
            }

            node.getModel().getLogContext().getAll().forEach(x -> x.setTimestamp(getTime(result.getEndMillis())));
            node.getModel().setStartTime(getTime(result.getStartMillis()));
            node.getModel().setEndTime(getTime(result.getEndMillis()));
        }
    }
}
 
Example #3
Source File: GatekeeperBehaviour.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
    if (!isThisSuiteListener(testResult)) {
        return;
    }
    if (method.isTestMethod()) {
        ITestNGMethod thisMethod = method.getTestMethod();
        ITestNGMethod[] allTestMethods = testResult.getTestContext().getAllTestMethods();
        ITestNGMethod firstMethod = allTestMethods[0];

        if (thisMethod.equals(firstMethod)) {
            Map<String, ISuiteResult> results = testResult.getTestContext().getSuite().getResults();
            if (hasFailedGatekeeperTest(results)) {
                throw new GatekeeperException(SKIP_MESSAGE);
            }
        } else {
            IResultMap skippedTests = testResult.getTestContext().getSkippedTests();
            if (anyTestsSkippedBecauseOfGatekeeper(skippedTests)) {
                throw new GatekeeperException(SKIP_MESSAGE);
            }
        }
    }
}
 
Example #4
Source File: FirstLastTestExecutionBehaviour.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
    if (!isThisSuiteListener(testResult)) {
        return;
    }
    if (method.isTestMethod()) {
        ITestNGMethod thisMethod = method.getTestMethod();
        ITestNGMethod[] allTestMethods = testResult.getTestContext().getAllTestMethods();
        ITestNGMethod firstMethod = allTestMethods[0];
        ITestNGMethod lastMethod = allTestMethods[allTestMethods.length - 1];

        if (!thisMethod.equals(firstMethod) && !thisMethod.equals(lastMethod)) {
            IResultMap success = testResult.getTestContext().getPassedTests();
            if (!success.getAllMethods().contains(firstMethod)) {
                throw new SkipException("Skipped because first method was not succcessfull");
            }
        }
    }
}
 
Example #5
Source File: CustomHTMLReporter.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
private SortedMap<IClass, List<ITestResult>> sortByTestClass(IResultMap results) {
    SortedMap<IClass, List<ITestResult>> sortedResults = new TreeMap<IClass, List<ITestResult>>(CLASS_COMPARATOR);
    for (ITestResult result : results.getAllResults()) {
        List<ITestResult> resultsForClass = sortedResults.get(result.getTestClass());
        if (resultsForClass == null) {
            resultsForClass = new ArrayList<>();
            sortedResults.put(result.getTestClass(), resultsForClass);
        }
        int index = Collections.binarySearch(resultsForClass, result, RESULT_COMPARATOR);
        if (index < 0) {
            index = Math.abs(index + 1);
        }
        resultsForClass.add(index, result);
    }
    return sortedResults;
}
 
Example #6
Source File: ExtentIReporterSuiteClassListenerAdapter.java    From extentreports-testng-adapter with Apache License 2.0 5 votes vote down vote up
private void buildTestNodes(ExtentTest suiteTest, IResultMap tests, Status status) {
    ExtentTest testNode;
    ExtentTest classNode;

    if (tests.size() > 0) {
        for (ITestResult result : tests.getAllResults()) {
            String className = result.getInstance().getClass().getSimpleName();

            if (classTestMap.containsKey(className)) {
                classNode = classTestMap.get(className);
            } else {
                classNode = suiteTest.createNode(className);
                classTestMap.put(className, classNode);
            }

            testNode = classNode.createNode(result.getMethod().getMethodName(),
                    result.getMethod().getDescription());

            String[] groups = result.getMethod().getGroups();
            ExtentTestCommons.assignGroups(testNode, groups);
            
            if (result.getThrowable() != null) {
                testNode.log(status, result.getThrowable());
            } else {
                testNode.log(status, "Test " + status.toString().toLowerCase() + "ed");
            }

            testNode.getModel().getLogContext().getAll().forEach(x -> x.setTimestamp(getTime(result.getEndMillis())));
            testNode.getModel().setStartTime(getTime(result.getStartMillis()));
            testNode.getModel().setEndTime(getTime(result.getEndMillis()));
        }
    }
}
 
Example #7
Source File: PowerEmailableReporter.java    From WebAndAppUITesting with GNU General Public License v3.0 5 votes vote down vote up
private void resultDetail(IResultMap tests) {
	for (ITestResult result : tests.getAllResults()) {
		ITestNGMethod method = result.getMethod();

		int methodId = getId(result);

		String cname = method.getTestClass().getName();
		m_out.println("<h2 id=\"m" + methodId + "\" name=\"m" + methodId + "\" >" + cname + ":"
				+ method.getMethodName() + "</h2>");
		Set<ITestResult> resultSet = tests.getResults(method);
		generateForResult(result, method, resultSet.size());
		m_out.println("<p class=\"totop\"><a href=\"#summary\">back to summary</a></p>");

	}
}
 
Example #8
Source File: PowerEmailableReporter.java    From WebAndAppUITesting with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get All tests id by class + method + parameters hash code.
 * 
 * @param context
 * @param suite
 */
private void getAllTestIds(ITestContext context, ISuite suite) {
	IResultMap passTests = context.getPassedTests();
	IResultMap failTests = context.getFailedTests();
	List<IInvokedMethod> invokedMethods = suite.getAllInvokedMethods();
	for (IInvokedMethod im : invokedMethods) {
		if (passTests.getAllMethods().contains(im.getTestMethod())
				|| failTests.getAllMethods().contains(im.getTestMethod())) {
			int testId = getId(im.getTestResult());
			// m_out.println("ALLtestid=" + testId);
			allRunTestIds.add(testId);
		}
	}
}
 
Example #9
Source File: TestReport.java    From PatatiumWebUi with Apache License 2.0 5 votes vote down vote up
@Override
public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory)
{
	List<ITestResult> list = new ArrayList<ITestResult>();
	for (ISuite suite : suites) {
		Map<String, ISuiteResult> suiteResults = suite.getResults();
		for (ISuiteResult suiteResult : suiteResults.values()) {
			ITestContext testContext = suiteResult.getTestContext();
			IResultMap passedTests = testContext.getPassedTests();
			IResultMap failedTests = testContext.getFailedTests();
			IResultMap skippedTests = testContext.getSkippedTests();
			IResultMap failedConfig = testContext.getFailedConfigurations();
			list.addAll(this.listTestResult(passedTests));
			list.addAll(this.listTestResult(failedTests));
			list.addAll(this.listTestResult(skippedTests));
			//list.addAll(this.listTestResult(failedConfig));
		}
	}
	CopyReportResources reportReource=new CopyReportResources();

	try {
		reportReource.copyResources();
	} catch (Exception e) {
		// TODO: handle exception
		e.printStackTrace();
	}
	this.sort(list);
	this.outputResult(list, outputDirectory+"/report.html");


}
 
Example #10
Source File: ScenarioTestListener.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
private String format(IResultMap skippedTests) {
  return skippedTests.getAllResults()
    .stream()
    .map(r -> " * " + r.getTestClass().getName() + "." + r.getName())
    .sorted()
    .collect(Collectors.joining("\n"));
}
 
Example #11
Source File: ListenerCommon.java    From stevia with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected int findFailed(ITestContext context) {
	IResultMap failedConfigurations = context.getFailedConfigurations();
	IResultMap skippedConfigurations = context.getSkippedConfigurations();
	
	int countfailed = 0;
	if (failedConfigurations!= null) {
		countfailed += failedConfigurations.size();
	}
	if (skippedConfigurations != null) {
		countfailed += skippedConfigurations.size();
	}
	return countfailed;
}
 
Example #12
Source File: TestReport.java    From PatatiumWebUi with Apache License 2.0 4 votes vote down vote up
private ArrayList<ITestResult> listTestResult(IResultMap resultMap){
	Set<ITestResult> results = resultMap.getAllResults();
	return new ArrayList<ITestResult>(results);
}
 
Example #13
Source File: GatekeeperBehaviour.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
private boolean anyTestsSkippedBecauseOfGatekeeper(IResultMap skippedTests) {
    return skippedTests.getAllResults().stream().anyMatch(result -> {
        return result.getThrowable() instanceof GatekeeperException;
    });
}
 
Example #14
Source File: EarlReporter.java    From teamengine with Apache License 2.0 4 votes vote down vote up
/**
 * Creates EARL statements from the given test results. A test result is
 * described by an Assertion resource. The TestResult and TestCase resources
 * are linked to the Assertion in accord with the EARL schema; the latter is
 * also linked to a TestRequirement.
 * 
 * @param earl
 *            An RDF Model containing EARL statements.
 * @param results
 *            The results of invoking a collection of test methods.
 */
void processTestResults(Model earl, IResultMap results) {
    for (ITestResult tngResult : results.getAllResults()) {
        // create earl:Assertion
        long endTime = tngResult.getEndMillis();
        GregorianCalendar calTime = new GregorianCalendar(TimeZone.getDefault());
        calTime.setTimeInMillis(endTime);
        Resource assertion = earl.createResource("assert-" + ++this.resultCount,
                EARL.Assertion);
        assertion.addProperty(EARL.mode, EARL.AutomaticMode);
        assertion.addProperty(EARL.assertedBy, this.assertor);
        assertion.addProperty(EARL.subject, this.testSubject);
        // link earl:TestResult to earl:Assertion
        Resource earlResult = earl.createResource("result-" + this.resultCount,
                EARL.TestResult);
        earlResult.addProperty(DCTerms.date, earl.createTypedLiteral(calTime));
        switch (tngResult.getStatus()) {
        case ITestResult.FAILURE:
            earlResult.addProperty(DCTerms.description, getDetailMessage(tngResult));
            if (AssertionError.class.isInstance(tngResult.getThrowable())) {
                earlResult.addProperty(EARL.outcome, EARL.Fail);
            } else { // an exception occurred
                earlResult.addProperty(EARL.outcome, EARL.CannotTell);
            }
            processResultAttributes(earlResult, tngResult);
            break;
        case ITestResult.SKIP:
            earlResult.addProperty(DCTerms.description, getDetailMessage(tngResult));
            earlResult.addProperty(EARL.outcome, EARL.NotTested);
            break;
        default:
            earlResult.addProperty(EARL.outcome, EARL.Pass);
            break;
        }
        assertion.addProperty(EARL.result, earlResult);
        // link earl:TestCase to earl:Assertion and earl:TestRequirement
        String testMethodName = tngResult.getMethod().getMethodName();
        String testClassName = tngResult.getTestClass().getName().replaceAll("\\.", "/");
        StringBuilder testCaseId = new StringBuilder(testClassName);
        testCaseId.append('#').append(testMethodName);
        Resource testCase = earl.createResource(testCaseId.toString(), EARL.TestCase);
        testCase.addProperty(DCTerms.title, breakIntoWords(testMethodName));
        String testDescr = tngResult.getMethod().getDescription();
        if (null != testDescr && !testDescr.isEmpty()) {
            testCase.addProperty(DCTerms.description, testDescr);
        }
        assertion.addProperty(EARL.test, testCase);
        String testReqName = tngResult.getTestContext().getName().replaceAll("\\s", "-");
        earl.createResource(testReqName).addProperty(DCTerms.hasPart, testCase);
    }
}