Refine search
/** Finds topmost position of the test method in the stack, or top of stack if <code>method</code> is not in it. */ public static int getTestRoot(StackTraceElement[] stack,ITestNGMethod method) { if(stack!=null) { String cname = method.getTestClass().getName(); for(int x=stack.length-1; x>=0; x--) { if(cname.equals(stack[x].getClassName()) && method.getMethodName().equals(stack[x].getMethodName())) { return x; } } return stack.length-1; } else { return -1; } }
private static String constructMethodNameUsingTestClass(String currentMethodName, ITestNGMethod m) { int lastIndex = currentMethodName.lastIndexOf('.'); if (lastIndex != -1) { return m.getTestClass().getRealClass().getName() + currentMethodName.substring(lastIndex); } return currentMethodName; }
@Test(description = "Test default methods defined in an interface should be run") public void testDefaultShouldRun() { ITestClass testClass = runTestWithDefaultMethods(); ITestNGMethod[] testMethods = testClass.getTestMethods(); Assert.assertEquals(testMethods.length, 1); Assert.assertEquals(testMethods[0].getMethodName(), "defaultMethodTest"); }
public NoOpTestClass(ITestClass testClass) { m_testClass= testClass.getRealClass(); m_beforeSuiteMethods= testClass.getBeforeSuiteMethods(); m_beforeTestConfMethods= testClass.getBeforeTestConfigurationMethods(); m_beforeGroupsMethods= testClass.getBeforeGroupsMethods(); m_beforeClassMethods= testClass.getBeforeClassMethods(); m_beforeTestMethods= testClass.getBeforeTestMethods(); m_afterSuiteMethods= testClass.getAfterSuiteMethods(); m_afterTestConfMethods= testClass.getAfterTestConfigurationMethods(); m_afterGroupsMethods= testClass.getAfterGroupsMethods(); m_afterClassMethods= testClass.getAfterClassMethods(); m_afterTestMethods= testClass.getAfterTestMethods(); m_instances= testClass.getInstances(true); m_instanceHashes= testClass.getInstanceHashCodes(); m_xmlTest = testClass.getXmlTest(); m_xmlClass = testClass.getXmlClass(); }
private static void getAllApplicableConfigs(Set<ITestNGMethod> configs, ITestClass iTestClass) { configs.addAll(Arrays.asList(iTestClass.getBeforeSuiteMethods())); configs.addAll(Arrays.asList(iTestClass.getAfterSuiteMethods())); configs.addAll(Arrays.asList(iTestClass.getBeforeTestConfigurationMethods())); configs.addAll(Arrays.asList(iTestClass.getAfterTestConfigurationMethods())); configs.addAll(Arrays.asList(iTestClass.getBeforeTestMethods())); configs.addAll(Arrays.asList(iTestClass.getAfterTestMethods())); configs.addAll(Arrays.asList(iTestClass.getBeforeClassMethods())); configs.addAll(Arrays.asList(iTestClass.getAfterClassMethods())); }
.append("<td>").append(cls.getRealClass().getName()).append("</td>\n") .append("<td> </td>") .append("<td> </td>") }; ITestNGMethod[][] methods = new ITestNGMethod[][] { cls.getTestMethods(), cls.getBeforeClassMethods(), cls.getBeforeTestMethods(), cls.getAfterTestMethods(), cls.getAfterClassMethods() };
String declaringClassName = m.getConstructorOrMethod().getMethod().getDeclaringClass().getName(); String testClassName = m.getTestClass().getName(); if (!classesToRerun.contains(testClassName) && declaringClassName.equals(testClassName)) if (m.isBeforeClassConfiguration() || m.isAfterClassConfiguration()) LOGGER.info("SKIPPING CONFIGURATION METHOD: " + declaringClassName + " : " + m.getMethodName()
if (m.isBeforeSuiteConfiguration()) { cls = "configuration-suite before"; } else if (m.isAfterSuiteConfiguration()) { cls = "configuration-suite after"; } else if (m.isBeforeTestConfiguration()) { cls = "configuration-test before"; } else if (m.isAfterTestConfiguration()) { String methodName = Model.getTestResultName(tr); if (!m.getTestClass().getName().equals(currentClass)) { if (!"".equals(currentClass)) { xsb.pop(D); xsb.addRequired(D, m.getTestClass().getName(), C, "chronological-class-name"); currentClass = m.getTestClass().getName();
private String readTestName(ITestNGMethod method) { if (method.isTest() && method.getInstance() instanceof WithName) { return ((WithName) method.getInstance()).getTestName(); } return method.getTestClass().getName() + "." + method.getMethodName(); }
@Override public String getContent(ISuite suite, XMLStringBuffer main) { XMLStringBuffer xsb = new XMLStringBuffer(main.getCurrentIndent()); SetMultiMap<Class<?>, ITestNGMethod> map = Maps.newSetMultiMap(); for (ITestNGMethod method : suite.getExcludedMethods()) { map.put(method.getTestClass().getRealClass(), method); } for (Class<?> c : map.keySet()) { xsb.push(D, C, "ignored-class-div"); xsb.addRequired(S, c.getName(), C, "ignored-class-name"); xsb.push(D, C, "ignored-methods-div"); for (ITestNGMethod m : map.get(c)) { xsb.addRequired(S, m.getMethodName(), C, "ignored-method-name"); xsb.addEmptyElement("br"); } xsb.pop(D); xsb.pop(D); } return xsb.toXML(); }
for (ITestResult result : tests.getAllResults()) { ITestNGMethod method = result.getMethod(); if(method.getConstructorOrMethod().getMethod().getAnnotation(SpecTest.class).testMethod().equals(METHOD.INDIRECT)){ List<String> groups = Arrays.asList(method.getGroups()); if (groups.contains("MUST") && result.getStatus() == ITestResult.FAILURE) { html.tr(class_("critical")); method.getTestClass().getName(), method.getMethodName()); html.td() .a(href("#" + method.getTestClass().getName() + "_" + method.getMethodName())) .write(normalizedName)._a();
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; }
private void init(ITestNGMethod method, ITestContext ctx, Throwable t, long start, long end) { m_throwable = t; m_instanceName = method.getTestClass().getName(); if (null == m_throwable) { m_status = ITestResult.SUCCESS; m_context = ctx; Object instance = method.getInstance(); m_name = m_method.getMethodName(); return; if (method.getTestClass().getTestName() != null) { m_name = method.getTestClass().getTestName(); return;
private boolean includeMethodFromIncludeExclude(ITestNGMethod tm, boolean isTestMethod) { boolean result = false; ConstructorOrMethod method = tm.getConstructorOrMethod(); Map<String, String> includedGroups = m_includedGroups; Map<String, String> excludedGroups = m_excludedGroups; String key; boolean hasTestClass = tm.getTestClass() != null; if (hasTestClass) { key = makeMethodName(tm.getTestClass().getRealClass().getName(), method.getName()); } else { key = MethodHelper.calculateMethodCanonicalName(tm);
/** Returns the name of the executed test. */ private static String getTestName(IInvokedMethod method) { return StringUtils.substringAfterLast(method.getTestMethod().getTestClass().getName(), ".") + "#" + method.getTestMethod().getConstructorOrMethod().getName(); }
@Override public int compare(IMethodInstance o1, IMethodInstance o2) { XmlTest test1 = o1.getMethod().getTestClass().getXmlTest(); XmlTest test2 = o2.getMethod().getTestClass().getXmlTest(); XmlClass class1 = o1.getMethod().getTestClass().getXmlClass(); XmlClass class2 = o2.getMethod().getTestClass().getXmlClass();
public SuiteMessage(final ISuite suite, final boolean startSuiteRun) { m_suiteName = suite.getName(); m_testMethodCount =suite.getInvokedMethods().size(); m_startSuite = startSuiteRun; Collection<ITestNGMethod> excludedMethods = suite.getExcludedMethods(); if (excludedMethods != null && excludedMethods.size() > 0) { m_excludedMethods = Lists.newArrayList(); m_descriptions = Maps.newHashMap(); for (ITestNGMethod m : excludedMethods) { String methodName = m.getTestClass().getName() + "." + m.getMethodName(); m_excludedMethods.add(methodName); if (m.getDescription() != null) m_descriptions.put(methodName, m.getDescription()); } } }
@Override public int compare(ITestNGMethod o1, ITestNGMethod o2) { String c1 = o1.getTestClass().getName(); String c2 = o2.getTestClass().getName(); return c1.compareTo(c2); } };
private boolean hasDependencies(ITestResult result) { String methodName = result.getMethod().getMethodName(); String className = result.getMethod().getTestClass().getName(); LOGGER.debug("current method: " + className + "." + methodName); // analyze all suite methods and return true if any of them depends on // existing method List<ITestNGMethod> methods = result.getTestContext().getSuite().getAllMethods(); for (ITestNGMethod method : methods) { LOGGER.debug("analyze method for dependency: " + method.getMethodName()); List<String> dependencies = Arrays.asList(method.getMethodsDependedUpon()); if (dependencies.contains(methodName) || dependencies.contains(className + "." + methodName)) { return true; } } return false; }
@Override public void beforeInvocation(IInvokedMethod method, ITestResult testResult, ITestContext context) { if (!method.isTestMethod()) { return; } // Note that TCK is processing test classes sequentially in one thread - see also SingleTestClassMethodInterceptor if (totalCountOfMethods == null) { totalCountOfMethods = context.getSuite().getAllMethods().size(); } String testClassName = method.getTestMethod().getTestClass().getName(); if (!testClassName.equals(lastTestClassName)) { processedTestClasses.incrementAndGet(); lastTestClassName = testClassName; } logger.log(Level.INFO, "Invoke {0}.{1}: {2}/{3} Failed tests: {4} ({5})", new Object[] { method.getTestMethod().getTestClass().getRealClass().getSimpleName(), method.getTestMethod().getMethodName(), testMethodInvocations.incrementAndGet(), totalCountOfMethods, context.getFailedTests().size(), processedTestClasses.get() }); }