Search in sources :

Example 1 with ITestClass

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

the class NeXMLSuiteResultWriter method addTestResult.

private void addTestResult(XMLStringBuffer xmlBuffer, ITestResult testResult) {
    Properties attribs = getTestResultAttributes(testResult);
    attribs.setProperty(NeXMLReporterConfig.ATTR_STATUS, getStatusString(testResult.getStatus()));
    ITestNGMethod method = testResult.getMethod();
    ITestClass testClass = method.getTestClass();
    String authors = this.getAuthors(testClass.getName(), method);
    String tcCase = this.getTestMethodAttr(NeXMLReporterConfig.ATTR_TC_NAME, testClass.getName(), method);
    String suites = this.getTestMethodAttr(NeXMLReporterConfig.ATTR_TC_SUITES, testClass.getName(), method);
    attribs.setProperty(NeXMLReporterConfig.ATTR_AUTHOR, authors);
    attribs.setProperty(NeXMLReporterConfig.ATTR_TC_NAME, tcCase);
    attribs.setProperty(NeXMLReporterConfig.ATTR_TC_SUITES, suites);
    xmlBuffer.push(NeXMLReporterConfig.TAG_TEST_METHOD, attribs);
    addTestMethodParams(xmlBuffer, testResult);
    addTestResultException(xmlBuffer, testResult);
    addTestResultOutput(xmlBuffer, testResult);
    if (config.isGenerateTestResultAttributes()) {
        addTestResultAttributes(xmlBuffer, testResult);
    }
    xmlBuffer.pop();
}
Also used : ITestClass(org.testng.ITestClass) ITestNGMethod(org.testng.ITestNGMethod) Properties(java.util.Properties)

Example 2 with ITestClass

use of org.testng.ITestClass 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 3 with ITestClass

use of org.testng.ITestClass in project gradle by gradle.

the class TestNGTestResultProcessorAdapter method onConfigurationFailure.

@Override
public void onConfigurationFailure(ITestResult testResult) {
    ITestNGMethod testMethod = testResult.getMethod();
    ITestClass testClass = testMethod.getTestClass();
    TestClassInfo classInfo;
    synchronized (lock) {
        if (!failedConfigurations.add(testResult)) {
            // workaround for bug in TestNG 6.2 (apparently fixed in some 6.3.x): listener is notified twice per event
            return;
        }
        classInfo = this.testClassInfo.get(testClass);
    }
    // Synthesise a test for the broken configuration method
    TestDescriptorInternal test = new DefaultTestMethodDescriptor(idGenerator.generateId(), testClass.getName(), testMethod.getMethodName());
    Object parentId = classInfo == null ? null : classInfo.id;
    resultProcessor.started(test, new TestStartEvent(testResult.getStartMillis(), parentId));
    resultProcessor.failure(test.getId(), testResult.getThrowable());
    resultProcessor.completed(test.getId(), new TestCompleteEvent(testResult.getEndMillis(), TestResult.ResultType.FAILURE));
}
Also used : ITestClass(org.testng.ITestClass) DefaultTestMethodDescriptor(org.gradle.api.internal.tasks.testing.DefaultTestMethodDescriptor) TestDescriptorInternal(org.gradle.api.internal.tasks.testing.TestDescriptorInternal) ITestNGMethod(org.testng.ITestNGMethod) TestStartEvent(org.gradle.api.internal.tasks.testing.TestStartEvent) TestCompleteEvent(org.gradle.api.internal.tasks.testing.TestCompleteEvent)

Example 4 with ITestClass

use of org.testng.ITestClass 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;
}
Also used : ITestClass(org.testng.ITestClass) ITestResult(org.testng.ITestResult) ITestNGMethod(org.testng.ITestNGMethod)

Aggregations

ITestClass (org.testng.ITestClass)4 ITestNGMethod (org.testng.ITestNGMethod)4 ITestResult (org.testng.ITestResult)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 DefaultTestMethodDescriptor (org.gradle.api.internal.tasks.testing.DefaultTestMethodDescriptor)1 TestCompleteEvent (org.gradle.api.internal.tasks.testing.TestCompleteEvent)1 TestDescriptorInternal (org.gradle.api.internal.tasks.testing.TestDescriptorInternal)1 TestStartEvent (org.gradle.api.internal.tasks.testing.TestStartEvent)1