Search in sources :

Example 11 with ITestNGMethod

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

the class DataProviderFactory method getDataProvider.

public static Object[][] getDataProvider(Annotation[] annotations, ITestContext context, ITestNGMethod m) {
    Map<String, String> testNameArgsMap = Collections.synchronizedMap(new HashMap<String, String>());
    Map<String, String> canonicalTestNameArgsMap = Collections.synchronizedMap(new HashMap<String, String>());
    Map<String, String> testMethodNameArgsMap = Collections.synchronizedMap(new HashMap<String, String>());
    Map<String, String> testMethodOwnerArgsMap = Collections.synchronizedMap(new HashMap<String, String>());
    Map<String, String> jiraArgsMap = Collections.synchronizedMap(new HashMap<String, String>());
    Map<String, String> testRailsArgsMap = Collections.synchronizedMap(new HashMap<String, String>());
    Map<String, String> bugArgsMap = Collections.synchronizedMap(new HashMap<String, String>());
    List<String> doNotRunTests = Collections.synchronizedList(new ArrayList<>());
    Object[][] provider = new Object[][] {};
    for (Annotation annotation : annotations) {
        try {
            Class<? extends Annotation> type = annotation.annotationType();
            String providerClass = "";
            for (Method method : type.getDeclaredMethods()) {
                if (method.getName().equalsIgnoreCase("classname")) {
                    providerClass = (String) method.invoke(annotation);
                    break;
                }
            }
            if (providerClass.isEmpty())
                continue;
            Class<?> clazz;
            Object object = null;
            try {
                clazz = Class.forName(providerClass);
                Constructor<?> ctor = clazz.getConstructor();
                object = ctor.newInstance();
            } catch (Exception e) {
                e.printStackTrace();
            }
            BaseDataProvider activeProvider = (BaseDataProvider) object;
            if (object instanceof com.qaprosoft.carina.core.foundation.dataprovider.core.impl.BaseDataProvider) {
                provider = ArrayUtils.addAll(provider, activeProvider.getDataProvider(annotation, context, m));
                testNameArgsMap.putAll(activeProvider.getTestNameArgsMap());
                canonicalTestNameArgsMap.putAll(activeProvider.getCanonicalTestNameArgsMap());
                testMethodNameArgsMap.putAll(activeProvider.getTestMethodNameArgsMap());
                testMethodOwnerArgsMap.putAll(activeProvider.getTestMethodOwnerArgsMap());
                jiraArgsMap.putAll(activeProvider.getJiraArgsMap());
                testRailsArgsMap.putAll(activeProvider.getTestRailsArgsMap());
                bugArgsMap.putAll(activeProvider.getBugArgsMap());
                doNotRunTests.addAll(activeProvider.getDoNotRunRowsIDs());
            }
        } catch (Exception e) {
            e.printStackTrace();
        // do nothing
        }
    }
    if (!GroupByMapper.getInstanceInt().isEmpty() || !GroupByMapper.getInstanceStrings().isEmpty()) {
        provider = getGroupedList(provider);
    }
    context.setAttribute(SpecialKeywords.TEST_NAME_ARGS_MAP, testNameArgsMap);
    context.setAttribute(SpecialKeywords.CANONICAL_TEST_NAME_ARGS_MAP, canonicalTestNameArgsMap);
    // TODO: analyze usage and remove TEST_METHOD_NAME_ARGS_MAP feature as soon as possible
    context.setAttribute(SpecialKeywords.TEST_METHOD_NAME_ARGS_MAP, testMethodNameArgsMap);
    context.setAttribute(SpecialKeywords.TEST_METHOD_OWNER_ARGS_MAP, testMethodOwnerArgsMap);
    context.setAttribute(SpecialKeywords.JIRA_ARGS_MAP, jiraArgsMap);
    context.setAttribute(SpecialKeywords.TESTRAIL_ARGS_MAP, testRailsArgsMap);
    context.setAttribute(SpecialKeywords.BUG_ARGS_MAP, bugArgsMap);
    context.setAttribute(SpecialKeywords.DO_NOT_RUN_TESTS, doNotRunTests);
    // clear group by settings
    GroupByMapper.getInstanceInt().clear();
    GroupByMapper.getInstanceStrings().clear();
    return provider;
}
Also used : ITestNGMethod(org.testng.ITestNGMethod) Method(java.lang.reflect.Method) Annotation(java.lang.annotation.Annotation) GroupByException(com.qaprosoft.carina.core.foundation.dataprovider.core.groupping.exceptions.GroupByException) BaseDataProvider(com.qaprosoft.carina.core.foundation.dataprovider.core.impl.BaseDataProvider)

Example 12 with ITestNGMethod

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

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

use of org.testng.ITestNGMethod in project java.webdriver by sayems.

the class TestNGListener method onFinish.

@Override
public void onFinish(ITestContext context) {
    Iterator<ITestResult> listOfFailedTests = context.getFailedTests().getAllResults().iterator();
    while (listOfFailedTests.hasNext()) {
        ITestResult failedTest = listOfFailedTests.next();
        ITestNGMethod method = failedTest.getMethod();
        if (context.getFailedTests().getResults(method).size() > 1) {
            listOfFailedTests.remove();
        } else {
            if (context.getPassedTests().getResults(method).size() > 0) {
                listOfFailedTests.remove();
            }
        }
    }
}
Also used : ITestResult(org.testng.ITestResult) ITestNGMethod(org.testng.ITestNGMethod)

Example 15 with ITestNGMethod

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

the class TestNGTestResultProcessorAdapter method onFinish.

@Override
public void onFinish(ITestContext iTestContext) {
    Object id;
    synchronized (lock) {
        id = testId.remove(iTestContext);
        xmlTestIds.remove(iTestContext.getCurrentXmlTest());
        for (ITestNGMethod method : iTestContext.getAllTestMethods()) {
            testMethodParentId.remove(method);
        }
    }
    resultProcessor.completed(id, new TestCompleteEvent(iTestContext.getEndDate().getTime()));
}
Also used : ITestNGMethod(org.testng.ITestNGMethod) TestCompleteEvent(org.gradle.api.internal.tasks.testing.TestCompleteEvent)

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