Search in sources :

Example 6 with ITestResult

use of org.testng.ITestResult in project arrow by NetEase.

the class NeXMLSuiteResultWriter method addTestResults.

private void addTestResults(XMLStringBuffer xmlBuffer, Set<ITestResult> testResults) {
    Map<String, List<ITestResult>> testsGroupedByClass = buildTestClassGroups(testResults);
    for (Map.Entry<String, List<ITestResult>> result : testsGroupedByClass.entrySet()) {
        Properties attributes = new Properties();
        String className = result.getKey();
        if (config.isSplitClassAndPackageNames()) {
            int dot = className.lastIndexOf('.');
            attributes.setProperty(NeXMLReporterConfig.ATTR_NAME, dot > -1 ? className.substring(dot + 1, className.length()) : className);
            attributes.setProperty(NeXMLReporterConfig.ATTR_PACKAGE, dot > -1 ? className.substring(0, dot) : "[default]");
        } else {
            attributes.setProperty(NeXMLReporterConfig.ATTR_NAME, className);
        }
        xmlBuffer.push(NeXMLReporterConfig.TAG_CLASS, attributes);
        List<ITestResult> sortedResults = result.getValue();
        Collections.sort(sortedResults);
        for (ITestResult testResult : sortedResults) {
            addTestResult(xmlBuffer, testResult);
        }
        xmlBuffer.pop();
    }
}
Also used : ITestResult(org.testng.ITestResult) ArrayList(java.util.ArrayList) List(java.util.List) Properties(java.util.Properties) Map(java.util.Map) IResultMap(org.testng.IResultMap)

Example 7 with ITestResult

use of org.testng.ITestResult in project arrow by NetEase.

the class PowerEmailableReporter method resultSummary.

/**
 * @param tests
 */
private void resultSummary(ISuite suite, IResultMap tests, String testname, String style, String details) {
    if (tests.getAllResults().size() > 0) {
        StringBuffer buff = new StringBuffer();
        String lastClassName = "";
        int mq = 0;
        int cq = 0;
        Map<String, Integer> methods = new HashMap<String, Integer>();
        Set<String> setMethods = new HashSet<String>();
        for (ITestNGMethod method : getMethodSet(tests, suite)) {
            m_row += 1;
            ITestClass testClass = method.getTestClass();
            String className = testClass.getName();
            if (mq == 0) {
                String id = (m_testIndex == null ? null : "t" + Integer.toString(m_testIndex));
                titleRow(testname + " &#8212; " + style + details, 5, id);
                m_testIndex = null;
            }
            if (!className.equalsIgnoreCase(lastClassName)) {
                if (mq > 0) {
                    cq += 1;
                    m_out.print("<tr class=\"" + style + (cq % 2 == 0 ? "even" : "odd") + "\">" + "<td");
                    if (mq > 1) {
                        m_out.print(" rowspan=\"" + mq + "\"");
                    }
                    m_out.println(">" + lastClassName + "</td>" + buff);
                }
                mq = 0;
                buff.setLength(0);
                lastClassName = className;
            }
            Set<ITestResult> resultSet = tests.getResults(method);
            long end = Long.MIN_VALUE;
            long start = Long.MAX_VALUE;
            for (ITestResult testResult : tests.getResults(method)) {
                if (testResult.getEndMillis() > end) {
                    end = testResult.getEndMillis();
                }
                if (testResult.getStartMillis() < start) {
                    start = testResult.getStartMillis();
                }
            }
            mq += 1;
            if (mq > 1) {
                buff.append("<tr class=\"" + style + (cq % 2 == 0 ? "odd" : "even") + "\">");
            }
            String description = method.getDescription();
            String testInstanceName = resultSet.toArray(new ITestResult[] {})[0].getTestName();
            // Calculate each test run times, the result shown in the html report.
            ITestResult[] results = resultSet.toArray(new ITestResult[] {});
            String methodName = method.getMethodName();
            if (setMethods.contains(methodName)) {
                methods.put(methodName, methods.get(methodName) + 1);
            } else {
                setMethods.add(methodName);
                methods.put(methodName, 0);
            }
            String parameterString = "";
            int count = 0;
            ITestResult result = null;
            if (results.length > methods.get(methodName)) {
                result = results[methods.get(methodName)];
                int testId = getId(result);
                for (Integer id : allRunTestIds) {
                    if (id.intValue() == testId)
                        count++;
                }
                Object[] parameters = result.getParameters();
                boolean hasParameters = parameters != null && parameters.length > 0;
                if (hasParameters) {
                    for (Object p : parameters) {
                        String pString = "null";
                        if (p != null) {
                            pString = p.toString();
                        }
                        parameterString = parameterString + Utils.escapeHtml(pString) + " ";
                    }
                }
            }
            int methodId = method.getTestClass().getName().hashCode();
            methodId = methodId + method.getMethodName().hashCode();
            if (result != null)
                methodId = methodId + (result.getParameters() != null ? Arrays.hashCode(result.getParameters()) : 0);
            buff.append("<td><a href=\"#m" + methodId + "\">" + qualifiedName(method) + " " + (description != null && description.length() > 0 ? "(\"" + description + "\")" : "") + "</a>" + (null == testInstanceName ? "" : "<br>(" + testInstanceName + ")") + "</td><td>" + this.getAuthors(className, method) + "</td><td class=\"numi\">" + resultSet.size() + "</td>" + "<td>" + (count == 0 ? "" : count) + "</td>" + "<td>" + parameterString + "</td>" + "<td>" + start + "</td>" + "<td class=\"numi\">" + (end - start) + "</td>" + "</tr>");
        }
        if (mq > 0) {
            cq += 1;
            m_out.print("<tr class=\"" + style + (cq % 2 == 0 ? "even" : "odd") + "\">" + "<td");
            if (mq > 1) {
                m_out.print(" rowspan=\"" + mq + "\"");
            }
            m_out.println(">" + lastClassName + "</td>" + buff);
        }
    }
}
Also used : ITestClass(org.testng.ITestClass) ITestResult(org.testng.ITestResult) HashMap(java.util.HashMap) ITestNGMethod(org.testng.ITestNGMethod) HashSet(java.util.HashSet)

Example 8 with ITestResult

use of org.testng.ITestResult in project powermock by powermock.

the class SimpleBaseTest method assertTestResultsEqual.

/**
 * Compare a list of ITestResult with a list of String method names,
 */
public static void assertTestResultsEqual(List<ITestResult> results, List<String> methods) {
    List<String> resultMethods = Lists.newArrayList();
    for (ITestResult r : results) {
        resultMethods.add(r.getMethod().getMethodName());
    }
    Assert.assertEquals(resultMethods, methods);
}
Also used : ITestResult(org.testng.ITestResult)

Example 9 with ITestResult

use of org.testng.ITestResult in project ats-framework by Axway.

the class AtsTestngListener method dependencyError.

private boolean dependencyError(ITestResult testResult, ITestContext context) {
    String[] dependentMethods = testResult.getMethod().getMethodsDependedUpon();
    List<ITestResult> failedTests = Arrays.asList(context.getFailedTests().getAllResults().toArray(new ITestResult[context.getFailedTests().getAllResults().size()]));
    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;
}
Also used : ITestResult(org.testng.ITestResult)

Example 10 with ITestResult

use of org.testng.ITestResult in project cucumber-jvm by cucumber.

the class TestNgReporter method result.

@Override
public void result(Result result) {
    logResult(result);
    if (Result.FAILED.equals(result.getStatus())) {
        ITestResult tr = getCurrentTestResult();
        tr.setThrowable(result.getError());
        tr.setStatus(ITestResult.FAILURE);
    } else if (Result.SKIPPED.equals(result)) {
        ITestResult tr = getCurrentTestResult();
        tr.setThrowable(result.getError());
        tr.setStatus(ITestResult.SKIP);
    } else if (Result.UNDEFINED.equals(result)) {
        ITestResult tr = getCurrentTestResult();
        tr.setThrowable(result.getError());
        tr.setStatus(ITestResult.FAILURE);
    }
}
Also used : ITestResult(org.testng.ITestResult)

Aggregations

ITestResult (org.testng.ITestResult)24 ArrayList (java.util.ArrayList)5 ITestNGMethod (org.testng.ITestNGMethod)5 Test (org.testng.annotations.Test)4 InvokedMethodNameListener (io.github.sskorol.listeners.InvokedMethodNameListener)3 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 List (java.util.List)2 EntryStream (one.util.streamex.EntryStream)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 ITestClass (org.testng.ITestClass)2 TestResultItem (com.qaprosoft.carina.core.foundation.report.TestResultItem)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 IInvokedMethod (org.testng.IInvokedMethod)1 IResultMap (org.testng.IResultMap)1 ITestContext (org.testng.ITestContext)1