Search in sources :

Example 16 with ITestResult

use of org.testng.ITestResult in project tomee by apache.

the class HTMLReporter method doWrap.

private List<ITestResult> doWrap(final List<ITestResult> raw) {
    final List<ITestResult> wrapped = new ArrayList<>(raw.size());
    final ClassLoader loader = Thread.currentThread().getContextClassLoader();
    for (final ITestResult result : raw) {
        wrapped.add(ITestResult.class.cast(Proxy.newProxyInstance(loader, API, new InvocationHandler() {

            @Override
            public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
                if (method.getName().equals("getParameters")) {
                    return new Object[method.getParameterTypes().length];
                }
                return method.invoke(result, args);
            }
        })));
    }
    return wrapped;
}
Also used : ITestResult(org.testng.ITestResult) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler)

Example 17 with ITestResult

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

the class NeXMLSuiteResultWriter method buildTestClassGroups.

private Map<String, List<ITestResult>> buildTestClassGroups(Set<ITestResult> testResults) {
    Map<String, List<ITestResult>> map = Maps.newHashMap();
    for (ITestResult result : testResults) {
        String className = result.getTestClass().getName();
        List<ITestResult> list = map.get(className);
        if (list == null) {
            list = Lists.newArrayList();
            map.put(className, list);
        }
        list.add(result);
    }
    return map;
}
Also used : ITestResult(org.testng.ITestResult) ArrayList(java.util.ArrayList) List(java.util.List)

Example 18 with ITestResult

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

the class PowerEmailableReporter method getMethodSet.

/**
 * Since the methods will be sorted chronologically, we want to return the
 * ITestNGMethod from the invoked methods.
 */
private Collection<ITestNGMethod> getMethodSet(IResultMap tests, ISuite suite) {
    List<IInvokedMethod> r = Lists.newArrayList();
    List<IInvokedMethod> invokedMethods = suite.getAllInvokedMethods();
    // Eliminate the repeat retry methods
    for (IInvokedMethod im : invokedMethods) {
        if (tests.getAllMethods().contains(im.getTestMethod())) {
            int testId = getId(im.getTestResult());
            if (!testIds.contains(testId)) {
                testIds.add(testId);
                r.add(im);
            }
        }
    }
    Arrays.sort(r.toArray(new IInvokedMethod[r.size()]), new TestSorter());
    List<ITestNGMethod> result = Lists.newArrayList();
    // Add all the invoked methods
    for (IInvokedMethod m : r) {
        result.add(m.getTestMethod());
    }
    for (ITestResult allResult : tests.getAllResults()) {
        int testId = getId(allResult);
        if (!testIds.contains(testId)) {
            result.add(allResult.getMethod());
        }
    }
    return result;
}
Also used : ITestResult(org.testng.ITestResult) ITestNGMethod(org.testng.ITestNGMethod) IInvokedMethod(org.testng.IInvokedMethod)

Example 19 with ITestResult

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

the class PowerEmailableReporter method resultDetail.

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

Example 20 with ITestResult

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

the class TestResultListener method onFinish.

@Override
public void onFinish(ITestContext testContext) {
    super.onFinish(testContext);
    // List of test results which we will delete later
    ArrayList<ITestResult> testsToBeRemoved = new ArrayList<ITestResult>();
    // collect all id's from passed test
    Set<Integer> passedTestIds = new HashSet<Integer>();
    for (ITestResult passedTest : testContext.getPassedTests().getAllResults()) {
        logger.info("PassedTests = " + passedTest.getName());
        passedTestIds.add(getId(passedTest));
    }
    // Eliminate the repeat methods
    Set<Integer> skipTestIds = new HashSet<Integer>();
    for (ITestResult skipTest : testContext.getSkippedTests().getAllResults()) {
        logger.info("skipTest = " + skipTest.getName());
        // id = class + method + dataprovider
        int skipTestId = getId(skipTest);
        if (skipTestIds.contains(skipTestId) || passedTestIds.contains(skipTestId)) {
            testsToBeRemoved.add(skipTest);
        } else {
            skipTestIds.add(skipTestId);
        }
    }
    // Eliminate the repeat failed methods
    Set<Integer> failedTestIds = new HashSet<Integer>();
    for (ITestResult failedTest : testContext.getFailedTests().getAllResults()) {
        logger.info("failedTest = " + failedTest.getName());
        // id = class + method + dataprovider
        int failedTestId = getId(failedTest);
        // version
        if (failedTestIds.contains(failedTestId) || passedTestIds.contains(failedTestId) || skipTestIds.contains(failedTestId)) {
            testsToBeRemoved.add(failedTest);
        } else {
            failedTestIds.add(failedTestId);
        }
    }
    // finally delete all tests that are marked
    for (Iterator<ITestResult> iterator = testContext.getFailedTests().getAllResults().iterator(); iterator.hasNext(); ) {
        ITestResult testResult = iterator.next();
        if (testsToBeRemoved.contains(testResult)) {
            logger.info("Remove repeat Fail Test: " + testResult.getName());
            iterator.remove();
        }
    }
}
Also used : ITestResult(org.testng.ITestResult) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

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