/** * @param names The list of names to check. * @return <code>true</code> if the current test's name matches with any of the given names. */ public boolean nameMatchesAny(List<String> names) { return names.contains(getName()); } }
/** * @param names The list of names to check. * @return <code>true</code> if the current test's name matches with any of the given names. */ public boolean nameMatchesAny(List<String> names) { return names.contains(getName()); } }
@Override public void run() { Utils.log("[SuiteWorker]", 4, "Running XML Test '" + testRunner.getTest().getName() + "' in Parallel"); runTest(testRunner); } }
/** * Ensures that the current suite doesn't contain any duplicate {@link XmlTest} instances. * If duplicates are found, then a {@link TestNGException} is raised. * * @param xmlSuite - The {@link XmlSuite} to work with. */ static void ensureNoDuplicateTestsArePresent(XmlSuite xmlSuite) { Set<String> testNames = Sets.newHashSet(); for (XmlTest test : xmlSuite.getTests()) { if (!testNames.add(test.getName())) { throw new TestNGException("Two tests in the same suite [" + xmlSuite.getName() + "] " + "cannot have the same name: " + test.getName()); } } }
private XmlSuite cloneIfSuiteContainTestsWithNamesMatchingAny(XmlSuite suite) { List<XmlTest> tests = Lists.newLinkedList(); for (XmlTest xt : suite.getTests()) { if (xt.nameMatchesAny(testNames)) { tests.add(xt); matchedTestNames.add(xt.getName()); matchedTests.add(xt); } } if (tests.isEmpty()) { return null; } return cleanClone(suite, tests); }
@Override public void run() { Utils.log( "[SuiteWorker]", 4, "Running XML Test '" + testRunner.getTest().getName() + "' in Parallel"); runTest(testRunner); } }
private XmlSuite cloneIfSuiteContainTestsWithNamesMatchingAny(XmlSuite suite) { List<XmlTest> tests = Lists.newLinkedList(); for (XmlTest xt : suite.getTests()) { if (xt.nameMatchesAny(testNames)) { tests.add(xt); matchedTestNames.add(xt.getName()); matchedTests.add(xt); } } if (tests.isEmpty()) { return null; } return cleanClone(suite, tests); }
public enum PriorityWeight { groupByInstance, preserveOrder, priority, dependsOnGroups, dependsOnMethods }
@Override public void onStart(ITestContext context) { messages.add("Executing " + context.getCurrentXmlTest().getName()); }
public static void addParams(XmlSuite suite, String suiteName, String testName, String sleepFor) { Map<String, String> parameters = new HashMap<>(); parameters.put("suiteName", suiteName); parameters.put("testName", testName); parameters.put("sleepFor", sleepFor); for (XmlTest test : suite.getTests()) { if (test.getName().equals(testName)) { test.setParameters(parameters); } } }
public static void addParams(XmlSuite suite, String suiteName, String testName, String sleepFor, String dataProviderParam) { Map<String, String> parameters = new HashMap<>(); parameters.put("suiteName", suiteName); parameters.put("testName", testName); parameters.put("sleepFor", sleepFor); parameters.put("dataProviderParam", dataProviderParam); for (XmlTest test : suite.getTests()) { if (test.getName().equals(testName)) { test.setParameters(parameters); } } }
@Override public void onConfigurationSuccess(ITestResult itr) { String xmlTestName = itr.getTestContext().getCurrentXmlTest().getName(); Integer count = CALLS.get(xmlTestName); if (count == null) { count = 0; } count++; CALLS.put(xmlTestName, count); }
@Override public void afterInvocation(IInvokedMethod method, ITestResult testResult) { XmlTest xmlTest = method.getTestMethod().getXmlTest(); afterInvocation.add(xmlTest.getName()); }
@Override public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { XmlTest xmlTest = method.getTestMethod().getXmlTest(); beforeInvocation.add(xmlTest.getName()); }
private static void extractClassNames( XmlSuite xmlSuite, List<String> testNames, List<String> classNames) { for (XmlTest xmlTest : xmlSuite.getTests()) { testNames.add(xmlTest.getName()); for (XmlClass xmlClass : xmlTest.getXmlClasses()) { classNames.add(xmlClass.getName()); } } }
public enum PriorityWeight { groupByInstance, preserveOrder, priority, dependsOnGroups, dependsOnMethods }
@Test(enabled = false) public void verifyTestContextInjection(ITestContext tc, XmlTest xmlTest) { TestNG tng = create(); tng.setTestClasses(new Class[] { Sample.class }); TestListenerAdapter tla = new TestListenerAdapter(); tng.addListener(tla); tng.run(); Assert.assertEquals(xmlTest.getName(), "Injection"); Assert.assertEquals(tla.getPassedTests().size(), 1); Assert.assertEquals(tla.getPassedTests().get(0).getMethod().getMethodName(), "f"); }
@Override public String getContent(ISuite suite, XMLStringBuffer main) { XMLStringBuffer xsb = new XMLStringBuffer(main.getCurrentIndent()); xsb.push("ul"); for (XmlTest test : suite.getXmlSuite().getTests()) { xsb.push("li"); int count = test.getXmlClasses().size(); String name = test.getName() + " (" + pluralize(count, "class") + ")"; xsb.addRequired(S, name, C, "test-name"); xsb.pop("li"); } xsb.pop("ul"); return xsb.toXML(); }
@Override public String getContent(ISuite suite, XMLStringBuffer main) { XMLStringBuffer xsb = new XMLStringBuffer(main.getCurrentIndent()); xsb.push("ul"); for (XmlTest test : suite.getXmlSuite().getTests()) { xsb.push("li"); int count = test.getXmlClasses().size(); String name = test.getName() + " (" + pluralize(count, "class") + ")"; xsb.addRequired(S, name, C, "test-name"); xsb.pop("li"); } xsb.pop("ul"); return xsb.toXML(); }
/** * Clone the <TT>source</TT> <CODE>XmlTest</CODE> by including: * - test attributes * - groups definitions * - parameters * * The <classes> sub element is ignored for the moment. * * @return a clone of the current XmlTest */ @Override public Object clone() { XmlTest result = new XmlTest(getSuite()); result.setName(getName()); result.setIncludedGroups(getIncludedGroups()); result.setExcludedGroups(getExcludedGroups()); result.setJUnit(isJUnit()); result.setParallel(getParallel()); result.setVerbose(getVerbose()); result.setParameters(getLocalParameters()); result.setXmlPackages(getXmlPackages()); result.setTimeOut(getTimeOut()); Map<String, List<String>> metagroups = getMetaGroups(); for (Map.Entry<String, List<String>> group: metagroups.entrySet()) { result.addMetaGroup(group.getKey(), group.getValue()); } return result; }