private boolean hasIncludedMethods() { for (XmlClass xmlClass : m_classes) { if (!xmlClass.getIncludedMethods().isEmpty()) { return true; } } return false; }
private boolean hasIncludedMethods() { for (XmlClass xmlClass : m_classes) { if (!xmlClass.getIncludedMethods().isEmpty()) { return true; } } return false; }
private static void toYaml(StringBuilder result, String sp2, XmlClass xc) { List<XmlInclude> im = xc.getIncludedMethods(); List<String> em = xc.getExcludedMethods(); String name = (im.isEmpty() && em.isEmpty()) ? "" : "name: "; result.append(sp2).append("- ").append(name).append(xc.getName()).append("\n"); if (!im.isEmpty()) { result.append(sp2).append(" includedMethods:\n"); for (XmlInclude xi : im) { toYaml(result, sp2 + " ", xi); } } if (!em.isEmpty()) { result.append(sp2).append(" excludedMethods:\n"); toYaml(result, sp2 + " ", em); } }
/** * @see java.lang.Runnable#run() */ @Override public void run() { for(Class<?> tc: classes) { List<XmlInclude> includedMethods = cim.getXmlClass(tc).getIncludedMethods(); List<String> methods = Lists.newArrayList(); for (XmlInclude inc: includedMethods) { methods.add(inc.getName()); } IJUnitTestRunner tr= ClassHelper.createTestRunner(TestRunner.this); tr.setInvokedMethodListeners(m_invokedMethodListeners); try { tr.run(tc, methods.toArray(new String[methods.size()])); } catch(Exception ex) { ex.printStackTrace(); } finally { runMethods.addAll(tr.getTestMethods()); } } }
private String findDescription(ITestAnnotation testAnnotation, XmlTest xmlTest) { String result = testAnnotation.getDescription(); if (result == null) { List<XmlClass> classes = xmlTest.getXmlClasses(); for (XmlClass c : classes) { if (c.getName().equals(m_method.getMethod().getDeclaringClass().getName())) { for (XmlInclude include : c.getIncludedMethods()) { if (include.getName().equals(m_method.getName())) { result = include.getDescription(); if (result != null) { break; } } } } } } return result; }
/** * Convenience method to cache the ordering numbers for methods. */ public List<Integer> getInvocationNumbers(String method) { if (m_failedInvocationNumbers == null) { m_failedInvocationNumbers = Maps.newHashMap(); for (XmlClass c : getXmlClasses()) { for (XmlInclude xi : c.getIncludedMethods()) { List<Integer> invocationNumbers = xi.getInvocationNumbers(); if (invocationNumbers.size() > 0) { String methodName = c.getName() + "." + xi.getName(); m_failedInvocationNumbers.put(methodName, invocationNumbers); } } } } List<Integer> result = m_failedInvocationNumbers.get(method); if (result == null) { // Don't use emptyList here since this list might end up receiving values if // the test run fails. return Lists.newArrayList(); } else { return result; } }
protected static void addMethods(XmlClass cls, String... methods) { int index = 0; for (String method : methods) { XmlInclude include = new XmlInclude(method, index++); cls.getIncludedMethods().add(include); } }
/** * Get local parameters of one include method from origin test xml. * @param srcXmlTest The {@link XmlTest} object that represents the source. * @param method the method we want to find its parameters * @return local parameters belong to one test method. */ private static Map<String, String> findMethodLocalParameters(XmlTest srcXmlTest, ITestNGMethod method) { Class clazz = method.getRealClass(); for (XmlClass c : srcXmlTest.getClasses()) { if (clazz == c.getSupportClass()) { for (XmlInclude xmlInclude : c.getIncludedMethods()) { if (xmlInclude.getName().equals(method.getMethodName())) { return xmlInclude.getLocalParameters(); } } } } return Collections.emptyMap(); }
@Override public Map<String, String> findMethodParameters(XmlTest test) { // Get the test+suite parameters Map<String, String> result = test.getAllParameters(); for (XmlClass xmlClass: test.getXmlClasses()) { if (xmlClass.getName().equals(getTestClass().getName())) { result.putAll(xmlClass.getLocalParameters()); for (XmlInclude include : xmlClass.getIncludedMethods()) { if (include.getName().equals(getMethodName())) { result.putAll(include.getLocalParameters()); break; } } } } return result; }
xsb.push("methods"); for (XmlInclude m : getIncludedMethods()) { xsb.getStringBuffer().append(m.toXml(indent + " "));
protected static XmlInclude createXmlInclude(XmlClass clazz, String method, int index, Integer... list) { XmlInclude include = new XmlInclude(method, Arrays.asList(list), index); include.setXmlClass(clazz); clazz.getIncludedMethods().add(include); return include; }
@Override public Map<String, String> findMethodParameters(XmlTest test) { // Get the test+suite parameters Map<String, String> result = test.getAllParameters(); for (XmlClass xmlClass : test.getXmlClasses()) { if (xmlClass.getName().equals(getTestClass().getName())) { result.putAll(xmlClass.getLocalParameters()); for (XmlInclude include : xmlClass.getIncludedMethods()) { if (include.getName().equals(getMethodName())) { result.putAll(include.getLocalParameters()); break; } } } } return result; }
protected static XmlInclude createXmlInclude(XmlClass clazz, String method) { XmlInclude include = new XmlInclude(method); include.setXmlClass(clazz); clazz.getIncludedMethods().add(include); return include; }
/** * Clone an XmlClass by copying all its components. */ @Override public Object clone() { XmlClass result = new XmlClass(getName(), getIndex(), loadClasses()); result.setExcludedMethods(getExcludedMethods()); result.setIncludedMethods(getIncludedMethods()); return result; }
public void setXmlClasses(List<XmlClass> classes) { m_classes = classes; for (XmlClass c : classes) { for (XmlInclude m : c.getIncludedMethods()) { checkMethod(c.getSupportClass(), m.getName()); String methodName = makeMethodName(c.getName(), m.getName()); m_includedMethods.put(methodName, m); } } }
public void addIncludedMethod(String className, String m) { XmlClass xmlClass= findClass(className); xmlClass.getIncludedMethods().add(new XmlInclude(m)); getTest().getXmlClasses().add(xmlClass); }
@Test public void testDescriptionInclusion() throws Exception { final String xml = getPathToResource("xml/simple-suite-with-method-desc.xml"); SuiteXmlParser parser = new SuiteXmlParser(); TestNGContentHandler handler = new TestNGContentHandler(xml, false); parser.parse(new FileInputStream(xml), handler); List<XmlInclude> includes = handler.getSuite().getTests().get(0).getXmlClasses().get(0).getIncludedMethods(); String desc = includes.get(0).getDescription(); Assert.assertEquals("simple-description", desc); }
@Test public void afterClassShouldRun() { XmlSuite s = createXmlSuite("S"); XmlTest t = createXmlTest(s, "T", Main.class.getName()); XmlClass c = t.getXmlClasses().get(0); c.getIncludedMethods().add(new XmlInclude("test1")); t.setPreserveOrder(true); TestNG tng = create(); tng.setXmlSuites(Arrays.asList(new XmlSuite[] { s })); Main.m_passed = false; tng.run(); Assert.assertTrue(Main.m_passed); } }
/** Clone an XmlClass by copying all its components. */ @Override public Object clone() { XmlClass result = new XmlClass(getName(), getIndex(), loadClasses()); result.setExcludedMethods(getExcludedMethods()); result.setIncludedMethods(getIncludedMethods()); return result; }
public void setXmlClasses(List<XmlClass> classes) { m_classes = classes; for (XmlClass c : classes) { for (XmlInclude m : c.getIncludedMethods()) { checkMethod(c.getSupportClass(), m.getName()); String methodName = makeMethodName(c.getName(), m.getName()); m_includedMethods.put(methodName, m); } } }