Search in sources :

Example 1 with ITestNGMethod

use of org.testng.ITestNGMethod in project bioformats by openmicroscopy.

the class OrderingListener method intercept.

@Override
public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
    IMethodInstance[] originalMethods = methods.toArray(new IMethodInstance[methods.size()]);
    Arrays.sort(originalMethods, new Comparator<IMethodInstance>() {

        @Override
        public int compare(IMethodInstance m1, IMethodInstance m2) {
            FormatReaderTest i1 = (FormatReaderTest) m1.getInstances()[0];
            FormatReaderTest i2 = (FormatReaderTest) m2.getInstances()[0];
            String instance1 = i1.getID();
            String instance2 = i2.getID();
            int instance = instance1.compareTo(instance2);
            if (instance != 0) {
                return instance;
            }
            ITestNGMethod method1 = m1.getMethod();
            ITestNGMethod method2 = m2.getMethod();
            return method1.getMethodName().compareTo(method2.getMethodName());
        }
    });
    List<IMethodInstance> orderedMethods = new ArrayList<IMethodInstance>();
    for (IMethodInstance method : originalMethods) {
        orderedMethods.add(method);
    }
    return orderedMethods;
}
Also used : ITestNGMethod(org.testng.ITestNGMethod) ArrayList(java.util.ArrayList) IMethodInstance(org.testng.IMethodInstance)

Example 2 with ITestNGMethod

use of org.testng.ITestNGMethod in project carina by qaprosoft.

the class ExpectedSkipManager method collectRules.

/**
 * Collect rules based on tests and its context
 *
 * @param testMethod
 * @param context
 * @return rules list
 */
private List<Class<? extends IRule>> collectRules(Method testMethod, ITestContext context) {
    List<Class<? extends IRule>> rules = new ArrayList<>();
    // collect rules from current class and method
    ExpectedSkip classSkipAnnotation = testMethod.getDeclaringClass().getAnnotation(ExpectedSkip.class);
    ExpectedSkip methodSkipAnnotation = testMethod.getAnnotation(ExpectedSkip.class);
    rules.addAll(getRulesFromAnnotation(classSkipAnnotation));
    rules.addAll(getRulesFromAnnotation(methodSkipAnnotation));
    // analyze all dependent methods and collect rules
    ITestNGMethod[] methods = context.getAllTestMethods();
    for (ITestNGMethod iTestNGMethod : methods) {
        if (iTestNGMethod.getMethodName().equalsIgnoreCase(testMethod.getName())) {
            String[] methodsDep = iTestNGMethod.getMethodsDependedUpon();
            for (String method : methodsDep) {
                rules.addAll(getDependentMethodsRules(method));
            }
        }
    }
    return rules;
}
Also used : ITestNGMethod(org.testng.ITestNGMethod) ArrayList(java.util.ArrayList) IRule(com.qaprosoft.carina.core.foundation.rule.IRule)

Example 3 with ITestNGMethod

use of org.testng.ITestNGMethod in project killbill by killbill.

the class GuicyKillbillTestSuite method afterMethodAlwaysRun.

@AfterMethod(alwaysRun = true)
public void afterMethodAlwaysRun(final Method method, final ITestResult result) throws Exception {
    if (hasFailed()) {
        return;
    }
    final String tag;
    switch(result.getStatus()) {
        case SUCCESS:
            tag = "SUCCESS";
            break;
        case FAILURE:
            tag = "!!! FAILURE !!!";
            break;
        case SKIP:
            tag = "SKIP";
            break;
        case SUCCESS_PERCENTAGE_FAILURE:
            tag = "SUCCESS WITHIN PERCENTAGE";
            break;
        case STARTED:
            tag = "STARTED";
            break;
        case CREATED:
            tag = "CREATED";
            break;
        default:
            tag = "UNKNOWN";
            break;
    }
    log.info("***************************************************************************************************");
    log.info("***   Ending test {}:{} {} ({} s.)", new Object[] { method.getDeclaringClass().getName(), method.getName(), tag, (result.getEndMillis() - result.getStartMillis()) / 1000 });
    log.info("***************************************************************************************************");
    if (!hasFailed && !result.isSuccess()) {
        // Ignore if the current test method is flaky
        final ITestNGMethod testNGMethod = result.getMethod();
        final boolean isFlakyTest = testNGMethod != null && testNGMethod.getRetryAnalyzer(result) != null && testNGMethod.getRetryAnalyzer(result) instanceof FlakyRetryAnalyzer;
        if (!isFlakyTest) {
            hasFailed = true;
        }
    }
}
Also used : FlakyRetryAnalyzer(org.killbill.billing.api.FlakyRetryAnalyzer) ITestNGMethod(org.testng.ITestNGMethod) AfterMethod(org.testng.annotations.AfterMethod)

Example 4 with ITestNGMethod

use of org.testng.ITestNGMethod 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 5 with ITestNGMethod

use of org.testng.ITestNGMethod 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)

Aggregations

ITestNGMethod (org.testng.ITestNGMethod)16 ITestResult (org.testng.ITestResult)5 ITestClass (org.testng.ITestClass)4 TestDescriptorInternal (org.gradle.api.internal.tasks.testing.TestDescriptorInternal)3 TestStartEvent (org.gradle.api.internal.tasks.testing.TestStartEvent)3 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 TestCompleteEvent (org.gradle.api.internal.tasks.testing.TestCompleteEvent)2 IMethodInstance (org.testng.IMethodInstance)2 DB (com.cloud.utils.db.DB)1 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)1 GroupByException (com.qaprosoft.carina.core.foundation.dataprovider.core.groupping.exceptions.GroupByException)1 BaseDataProvider (com.qaprosoft.carina.core.foundation.dataprovider.core.impl.BaseDataProvider)1 IRule (com.qaprosoft.carina.core.foundation.rule.IRule)1 Annotation (java.lang.annotation.Annotation)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1