Refine search
protected static void invokeMethodConsideringTimeout(ITestNGMethod tm, ConstructorOrMethod method, Object targetInstance, Object[] params, ITestResult testResult) throws Throwable { if (MethodHelper.calculateTimeOut(tm) <= 0) { MethodInvocationHelper.invokeMethod(method.getMethod(), targetInstance, params); } else { MethodInvocationHelper.invokeWithTimeout(tm, targetInstance, params, testResult); if (!testResult.isSuccess()) { // A time out happened Throwable ex = testResult.getThrowable(); testResult.setStatus(ITestResult.FAILURE); testResult.setThrowable(ex.getCause() == null ? ex : ex.getCause()); throw testResult.getThrowable(); } } }
/** * Create the test methods that belong to this class (rejects * all those that belong to a different class). */ private ITestNGMethod[] createTestMethods(ITestNGMethod[] methods) { List<ITestNGMethod> vResult = Lists.newArrayList(); for (ITestNGMethod tm : methods) { ConstructorOrMethod m = tm.getConstructorOrMethod(); if (m.getDeclaringClass().isAssignableFrom(m_testClass)) { for (Object o : iClass.getInstances(false)) { log(4, "Adding method " + tm + " on TestClass " + m_testClass); vResult.add(new TestNGMethod(/* tm.getRealClass(), */ m.getMethod(), annotationFinder, xmlTest, o)); } } else { log(4, "Rejecting method " + tm + " for TestClass " + m_testClass); } } return vResult.toArray(new ITestNGMethod[vResult.size()]); }
private void generateExcludedMethodsReport(XmlSuite xmlSuite, ISuite suite) { Collection<ITestNGMethod> excluded = suite.getExcludedMethods(); StringBuilder sb2 = new StringBuilder("<h2>Methods that were not run</h2><table>\n"); for (ITestNGMethod method : excluded) { ConstructorOrMethod m = method.getConstructorOrMethod(); if (m != null) { sb2.append("<tr><td>") .append(m.getDeclaringClass().getName()).append(".").append(m.getName()); String description = method.getDescription(); if(isStringNotEmpty(description)) { sb2.append("<br/>").append(SP2).append("<i>").append(description).append("</i>"); } sb2.append("</td></tr>\n"); } } sb2.append("</table>"); Utils.writeFile(getOutputDirectory(xmlSuite), METHODS_NOT_RUN, sb2.toString()); }
@Override public boolean accept(ConstructorOrMethod method) { return method.getName().startsWith("test") && method.getParameterTypes().length == 0; } }, cls);
public String getSimpleName() { return m_method.getDeclaringClass().getSimpleName() + "." + m_method.getName(); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((getConstructor() == null) ? 0 : getConstructor().hashCode()); result = prime * result + ((getMethod() == null) ? 0 : getMethod().hashCode()); return result; }
private Properties getTestResultAttributes(ITestResult testResult) { Properties attributes = new Properties(); if (!testResult.getMethod().isTest()) { attributes.setProperty(XMLReporterConfig.ATTR_IS_CONFIG, "true"); attributes.setProperty(XMLReporterConfig.ATTR_NAME, testResult.getMethod().getMethodName()); String testInstanceName = testResult.getTestName(); if (null != testInstanceName) { attributes.setProperty(XMLReporterConfig.ATTR_TEST_INSTANCE_NAME, testInstanceName); String description = testResult.getMethod().getDescription(); if (!Utils.isStringEmpty(description)) { attributes.setProperty(XMLReporterConfig.ATTR_DESC, description); ConstructorOrMethod cm = testResult.getMethod().getConstructorOrMethod(); Test testAnnotation; if (cm.getMethod() != null) { testAnnotation = cm.getMethod().getAnnotation(Test.class); if (testAnnotation != null) { String dataProvider = testAnnotation.dataProvider();
Method testMethod = testResult.getMethod().getConstructorOrMethod().getMethod(); boolean beforeCallbacksExecuted = false;
@Override public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { if (method.isTestMethod()) { Method testMethod = method.getTestMethod().getConstructorOrMethod().getMethod(); TestCoverage.INSTANCE.setCurrentTestMethod(testMethod); } }
/** * This method helps in creating a Test runner neutral object that represents a method. * * @param method * - An {@link IInvokedMethod} that represents the current invoked method. * @param result * - An {@link ITestResult} object that represents a test result. * @return - A {@link InvokedMethodInformation} that represents the current invoked method. */ public static InvokedMethodInformation getInvokedMethodInformation(IInvokedMethod method, ITestResult result) { logger.entering(new Object[] { method, result }); InvokedMethodInformation methodInfo = new InvokedMethodInformation(); methodInfo.setMethodParameters(result.getParameters()); methodInfo.setActualMethod(method.getTestMethod().getConstructorOrMethod().getMethod()); methodInfo.setTestMethodAttributes(extractAttributes(result)); methodInfo.setCurrentMethodName(method.getTestMethod().getMethodName()); methodInfo.setCurrentTestName(result.getTestContext().getCurrentXmlTest().getName()); methodInfo.setTestResultSuccess(result.isSuccess()); methodInfo.setException(result.getThrowable()); methodInfo.setMethodsDependedUpon(method.getTestMethod().getMethodsDependedUpon()); logger.exiting(methodInfo); return methodInfo; }
private static boolean annotationPresent(IInvokedMethod method, Class<? extends Annotation> clazz) { return method.getTestMethod().getConstructorOrMethod().getMethod().isAnnotationPresent(clazz); }
assert null != testMethod.getTestClass() : "COULDN'T FIND TESTCLASS FOR " + testMethod.getRealClass(); if (!MethodHelper.isEnabled(testMethod.getConstructorOrMethod().getMethod(), m_annotationFinder)) { Throwable throwable = tr.getThrowable(); if (throwable instanceof TestNGException) { tr.setStatus(ITestResult.FAILURE); m_notifier.addFailedTest(testMethod, tr); } else { tr.setStatus(ITestResult.SKIP); m_notifier.addSkippedTest(testMethod, tr); testMethod.getConstructorOrMethod().getMethod(), testContext); testMethod.getConstructorOrMethod().getMethod(), testContext);
private boolean isLowPriority(IInvokedMethod method) { int low = method.getTestMethod().getPriority(); for (ITestNGMethod test : method.getTestMethod().getTestClass().getTestMethods()) { // ensures all test methods have the @Test annotation. Throw exception if that's not the case if (!isAnnotatedWithTest(test.getConstructorOrMethod().getMethod())) { throw new IllegalStateException( "Session sharing requires all test methods to define a priority via the @Test annotation."); } if (test.getEnabled() && test.getPriority() < low) { return false; } } Test t = method.getTestMethod().getConstructorOrMethod().getMethod().getAnnotation(Test.class); // If there is an existing session and the test method has a DP then don't create a session // For a data driven test method with the first data the session must be created // Hence return true if currentInvocationCount is 1 otherwise utilize the same session // by returning false int currentInvocationCount = method.getTestMethod().getCurrentInvocationCount(); if (!t.dataProvider().isEmpty()) { return currentInvocationCount == 0; } return true; }
void addSelenideErrorListener(ITestResult result) { boolean listenerAlreadyAdded = SelenideLogger.hasListener(LISTENER_SOFT_ASSERT); boolean hasSoftAssertListener = shouldIntercept(result.getTestClass().getRealClass()); boolean isTestMethod = shouldIntercept(result.getMethod().getConstructorOrMethod().getMethod()); if (hasSoftAssertListener && isTestMethod && !listenerAlreadyAdded) { SelenideLogger.addListener(LISTENER_SOFT_ASSERT, new ErrorsCollector()); } else if (hasSoftAssertListener && !listenerAlreadyAdded) { SelenideLogger.addListener(LISTENER_SOFT_ASSERT, new ErrorsCollector()); } }
private static String getName(ITestResult result) { String testName = result.getName(); String methodName = result.getMethod().getConstructorOrMethod().getName(); String name; if (testName.contains(methodName)) { name = methodName; } else { name = testName + "#" + methodName; } if (result.getParameters().length != 0) { name = name + "(" + Joiner.on(",").useForNull("null").join(getParameterNames(result.getParameters())) + ")"; } return name; }
ITestContext context) { if (testMethod.getTestClass() == null) { throw new IllegalArgumentException( "COULDN'T FIND TESTCLASS FOR " + testMethod.getRealClass()); testMethod.getConstructorOrMethod().getMethod(), annotationFinder())) { testMethod, System.currentTimeMillis(), new Throwable(okToProceed)); m_notifier.addSkippedTest(testMethod, result); InvokedMethod invokedMethod = new InvokedMethod(result.getInstance(), testMethod, System.currentTimeMillis(), result); invokeListenersForSkippedTestResult(result, invokedMethod);
arguments.setTestClass(tm.getTestClass()); testResult.setStatus(ITestResult.STARTED); Object inst = tm.getInstance(); if (inst == null) { inst = arguments.getInstance(); ConstructorOrMethod method = tm.getConstructorOrMethod(); new InvokedMethod(arguments.getInstance(), tm, System.currentTimeMillis(), testResult); runInvokedMethodListeners(BEFORE_INVOCATION, invokedMethod, testResult); testResult.setStatus(ITestResult.SKIP); runInvokedMethodListeners(AFTER_INVOCATION, invokedMethod, testResult); handleConfigurationSkip( tm.getConstructorOrMethod().getMethod(), arguments.getParameters(), arguments.getParameterValues(), m_testContext, arguments.getTestMethodResult()); testResult.setParameters(parameters);
/** Hook executed after each test method. */ @AfterMethod( groups = {"isolated", "short", "long", "stress", "duration"}, alwaysRun = true) public void afterTestMethod(ITestResult tr) throws Exception { if (isCcmEnabled(tr.getMethod().getConstructorOrMethod().getMethod())) { if (tr.getStatus() == ITestResult.FAILURE) { errorOut(); } if (erroredOut || testMode == PER_METHOD) { closeCloseables(); closeTestCluster(); } if (testMode == PER_METHOD) closeTestContext(); } }
@Override public void onTestStart(ITestResult result) { TestPhase.setActivePhase(Phase.METHOD); // handle expected skip Method testMethod = result.getMethod().getConstructorOrMethod().getMethod(); if (ExpectedSkipManager.getInstance().isSkip(testMethod, result.getTestContext())) { skipExecution("Based on rule listed above"); } super.onTestStart(result); }
@Override public void beforeInvocation(IInvokedMethod testMethod, ITestResult testResult) { // Check to see if the class or method is annotated with 'CassandraVersion', if so ensure the // version we are testing with meets the requirement, if not a SkipException is thrown // and this test is skipped. ITestNGMethod testNgMethod = testResult.getMethod(); ConstructorOrMethod constructorOrMethod = testNgMethod.getConstructorOrMethod(); Class<?> clazz = testNgMethod.getInstance().getClass(); if (clazz != null) { do { if (scanAnnotatedElement(clazz)) break; } while (!(clazz = clazz.getSuperclass()).equals(Object.class)); } Method method = constructorOrMethod.getMethod(); if (method != null) { scanAnnotatedElement(method); } }