Search in sources :

Example 1 with IInvokedMethod

use of org.testng.IInvokedMethod in project openstack4j by ContainX.

the class SkipTestListener method beforeInvocation.

@Override
public void beforeInvocation(IInvokedMethod iim, ITestResult itr) {
    Method method = iim.getTestMethod().getConstructorOrMethod().getMethod();
    // Check if method is annotated with @SkipTest
    if (method.isAnnotationPresent(SkipTest.class)) {
        SkipTest skipAnnotation = method.getAnnotation(SkipTest.class);
        String httpExecutorName = HttpExecutor.create().getExecutorName();
        // Annotation connector parameter can be a regex like ".*"
        if (httpExecutorName.matches(skipAnnotation.connector())) {
            StringBuilder message = new StringBuilder();
            message.append(String.format("Skip test %s for connector %s", method.getName(), httpExecutorName));
            if (skipAnnotation.issue() > 0) {
                message.append(String.format(" due to issue %s", skipAnnotation.issue()));
            }
            if (!skipAnnotation.description().isEmpty()) {
                message.append(String.format(": %s", skipAnnotation.description()));
            }
            // Skip Test
            Logger.getLogger(getClass().getName()).warning(message.toString());
            throw new SkipException(message.toString());
        }
    }
}
Also used : IInvokedMethod(org.testng.IInvokedMethod) Method(java.lang.reflect.Method) SkipException(org.testng.SkipException)

Example 2 with IInvokedMethod

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

the class PowerEmailableReporter method getAllTestIds.

/**
	 * Get All tests id by class + method + parameters hash code.
	 * @param context
	 * @param suite
	 * @author kevinkong
	 */
private void getAllTestIds(ITestContext context, ISuite suite) {
    IResultMap passTests = context.getPassedTests();
    IResultMap failTests = context.getFailedTests();
    List<IInvokedMethod> invokedMethods = suite.getAllInvokedMethods();
    for (IInvokedMethod im : invokedMethods) {
        if (passTests.getAllMethods().contains(im.getTestMethod()) || failTests.getAllMethods().contains(im.getTestMethod())) {
            int testId = getId(im.getTestResult());
            // m_out.println("ALLtestid=" + testId);
            allRunTestIds.add(testId);
        }
    }
}
Also used : IResultMap(org.testng.IResultMap) IInvokedMethod(org.testng.IInvokedMethod)

Example 3 with IInvokedMethod

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

Aggregations

IInvokedMethod (org.testng.IInvokedMethod)3 Method (java.lang.reflect.Method)1 IResultMap (org.testng.IResultMap)1 ITestNGMethod (org.testng.ITestNGMethod)1 ITestResult (org.testng.ITestResult)1 SkipException (org.testng.SkipException)1