Best Testng code snippet using org.testng.xml.XmlSuite.getGroupByInstances
Source:XmlSuite.java
...430 final ParallelMode parallel= getParallel();431 if(parallel != null && !DEFAULT_PARALLEL.equals(parallel)) {432 p.setProperty("parallel", parallel.toString());433 }434 XmlUtils.setProperty(p, "group-by-instances", String.valueOf(getGroupByInstances()),435 DEFAULT_GROUP_BY_INSTANCES.toString());436 XmlUtils.setProperty(p, "configfailurepolicy", getConfigFailurePolicy().toString(),437 DEFAULT_CONFIG_FAILURE_POLICY.toString());438 XmlUtils.setProperty(p, "thread-count", String.valueOf(getThreadCount()),439 DEFAULT_THREAD_COUNT.toString());440 XmlUtils.setProperty(p, "data-provider-thread-count", String.valueOf(getDataProviderThreadCount()),441 DEFAULT_DATA_PROVIDER_THREAD_COUNT.toString());442 if (! DEFAULT_JUNIT.equals(m_isJUnit)) {443 p.setProperty("junit", m_isJUnit != null ? m_isJUnit.toString() : "false"); // TESTNG-141444 }445 XmlUtils.setProperty(p, "skipfailedinvocationcounts", m_skipFailedInvocationCounts.toString(),446 DEFAULT_SKIP_FAILED_INVOCATION_COUNTS.toString());447 if(null != m_objectFactory) {448 p.setProperty("object-factory", m_objectFactory.getClass().getName());449 }450 if (isStringNotEmpty(m_parentModule)) {451 p.setProperty("parent-module", getParentModule());452 }453 if (isStringNotEmpty(m_guiceStage)) {454 p.setProperty("guice-stage", getGuiceStage());455 }456 XmlUtils.setProperty(p, "allow-return-values", String.valueOf(getAllowReturnValues()),457 DEFAULT_ALLOW_RETURN_VALUES.toString());458 xsb.push("suite", p);459 XmlUtils.dumpParameters(xsb, m_parameters);460 if (hasElements(m_listeners)) {461 xsb.push("listeners");462 for (String listenerName: m_listeners) {463 Properties listenerProps = new Properties();464 listenerProps.setProperty("class-name", listenerName);465 xsb.addEmptyElement("listener", listenerProps);466 }467 xsb.pop("listeners");468 }469 if (hasElements(getXmlPackages())) {470 xsb.push("packages");471 for (XmlPackage pack : getXmlPackages()) {472 xsb.getStringBuffer().append(pack.toXml(" "));473 }474 xsb.pop("packages");475 }476 if (getXmlMethodSelectors() != null) {477 xsb.getStringBuffer().append(getXmlMethodSelectors().toXml(" "));478 } else {479 // deprecated480 if (hasElements(getMethodSelectors())) {481 xsb.push("method-selectors");482 for (XmlMethodSelector selector : getMethodSelectors()) {483 xsb.getStringBuffer().append(selector.toXml(" "));484 }485 xsb.pop("method-selectors");486 }487 }488 List<String> suiteFiles = getSuiteFiles();489 if (suiteFiles.size() > 0) {490 xsb.push("suite-files");491 for (String sf : suiteFiles) {492 Properties prop = new Properties();493 prop.setProperty("path", sf);494 xsb.addEmptyElement("suite-file", prop);495 }496 xsb.pop("suite-files");497 }498 List<String> included = getIncludedGroups();499 List<String> excluded = getExcludedGroups();500 if (hasElements(included) || hasElements(excluded)) {501 xsb.push("groups");502 xsb.push("run");503 for (String g : included) {504 xsb.addEmptyElement("include", "name", g);505 }506 for (String g : excluded) {507 xsb.addEmptyElement("exclude", "name", g);508 }509 xsb.pop("run");510 xsb.pop("groups");511 }512 if (m_xmlGroups != null) {513 xsb.getStringBuffer().append(m_xmlGroups.toXml(" "));514 }515 for (XmlTest test : getTests()) {516 xsb.getStringBuffer().append(test.toXml(" "));517 }518 xsb.pop("suite");519 return xsb.toXML();520 }521 @Tag(name = "method-selectors")522 public void setXmlMethodSelectors(XmlMethodSelectors xms) {523 m_xmlMethodSelectors = xms;524 }525 private XmlMethodSelectors getXmlMethodSelectors() {526 return m_xmlMethodSelectors;527 }528 /**529 * {@inheritDoc}530 */531 @Override532 public String toString() {533 StringBuilder result = new StringBuilder("[Suite: \"").append( m_name).append( "\" ");534 for (XmlTest t : m_tests) {535 result.append(" ").append( t.toString()).append(' ');536 }537 for (XmlMethodSelector ms : m_methodSelectors) {538 result.append(" methodSelector:").append(ms);539 }540 result.append(']');541 return result.toString();542 }543 /**544 * {@inheritDoc}545 * Note that this is not a full clone: XmlTest children are not cloned by this546 * method.547 */548 @Override549 public Object clone() {550 XmlSuite result = shallowCopy();551 result.setExcludedGroups(getExcludedGroups());552 result.setIncludedGroups(getIncludedGroups());553 result.setGroupByInstances(getGroupByInstances());554 result.setGroups(getGroups());555 result.setMethodSelectors(getXmlMethodSelectors());556 result.setPackages(getPackages());557 result.setParentSuite(getParentSuite());558 result.setPreserveOrder(getPreserveOrder());559 result.setSuiteFiles(getSuiteFiles());560 result.setTests(getTests());561 result.setXmlMethodSelectors(getXmlMethodSelectors());562 return result;563 }564 /**565 * This method returns a shallow cloned version. {@link XmlTest} are not copied by this method.566 * @return - A Shallow copied version of {@link XmlSuite}.567 */568 public XmlSuite shallowCopy() {569 XmlSuite result = new XmlSuite();570 result.setName(getName());571 result.setFileName(getFileName());572 result.setListeners(getListeners());573 result.setParallel(getParallel());574 result.setParentModule(getParentModule());575 result.setGuiceStage(getGuiceStage());576 result.setConfigFailurePolicy(getConfigFailurePolicy());577 result.setThreadCount(getThreadCount());578 result.setDataProviderThreadCount(getDataProviderThreadCount());579 result.setParameters(getParameters());580 result.setVerbose(getVerbose());581 result.setXmlPackages(getXmlPackages());582// result.setBeanShellExpression(getExpression());583 result.setMethodSelectors(getMethodSelectors());584 result.setJUnit(isJUnit()); // TESTNG-141585 result.setSkipFailedInvocationCounts(skipFailedInvocationCounts());586 result.setObjectFactory(getObjectFactory());587 result.setAllowReturnValues(getAllowReturnValues());588 result.setTimeOut(getTimeOut());589 return result;590 }591 /**592 * Sets the timeout.593 *594 * @param timeOut the timeout.595 */596 public void setTimeOut(String timeOut) {597 m_timeOut = timeOut;598 }599 /**600 * Returns the timeout.601 * @return the timeout.602 */603 public String getTimeOut() {604 return m_timeOut;605 }606 607 /**608 * Returns the timeout as a long value specifying the default value to be used if609 * no timeout was specified.610 *611 * @param def the the default value to be used if no timeout was specified.612 * @return the timeout as a long value specifying the default value to be used if613 * no timeout was specified.614 */615 public long getTimeOut(long def) {616 long result = def;617 if (m_timeOut != null) {618 result = Long.parseLong(m_timeOut);619 }620 621 return result;622 }623 /**624 * Sets the suite files.625 *626 * @param files the suite files.627 */628 public void setSuiteFiles(List<String> files) {629 m_suiteFiles = files;630 }631 632 /**633 * Returns the suite files.634 * @return the suite files.635 */636 public List<String> getSuiteFiles() {637 return m_suiteFiles;638 }639 public void setListeners(List<String> listeners) {640 m_listeners = listeners;641 }642 public List<String> getListeners() {643 if (m_parentSuite != null) {644 List<String> listeners = m_parentSuite.getListeners();645 for (String listener : listeners) {646 if (!m_listeners.contains(listener)) {647 m_listeners.add(listener);648 }649 }650 }651 return m_listeners;652 }653 public void setDataProviderThreadCount(int count) {654 m_dataProviderThreadCount = count;655 }656 public int getDataProviderThreadCount() {657 String s = System.getProperty("dataproviderthreadcount");658 if (s != null) {659 try {660 return Integer.parseInt(s);661 } catch(NumberFormatException nfe) {662 System.err.println("Parsing System property 'dataproviderthreadcount': " + nfe);663 }664 }665 return m_dataProviderThreadCount;666 }667 public void setParentSuite(XmlSuite parentSuite) {668 m_parentSuite = parentSuite;669 updateParameters();670 }671 public XmlSuite getParentSuite() {672 return m_parentSuite;673 }674 public List<XmlSuite> getChildSuites() {675 return m_childSuites;676 }677 @Override678 public int hashCode() {679 final int prime = 31;680 int result = 1;681 result = prime682 * result683 + ((m_configFailurePolicy == null) ? 0 : m_configFailurePolicy684 .hashCode());685 result = prime * result + m_dataProviderThreadCount;686 result = prime * result687 + ((m_expression == null) ? 0 : m_expression.hashCode());688 result = prime * result689 + ((m_fileName == null) ? 0 : m_fileName.hashCode());690 result = prime * result691 + ((m_isJUnit == null) ? 0 : m_isJUnit.hashCode());692 result = prime * result693 + ((m_listeners == null) ? 0 : m_listeners.hashCode());694 result = prime * result695 + ((m_methodSelectors == null) ? 0 : m_methodSelectors.hashCode());696 result = prime * result + ((m_name == null) ? 0 : m_name.hashCode());697 result = prime * result698 + ((m_objectFactory == null) ? 0 : m_objectFactory.hashCode());699 result = prime * result700 + ((m_parallel == null) ? 0 : m_parallel.hashCode());701// result = prime * result702// + ((m_parameters == null) ? 0 : m_parameters.hashCode());703// result = prime * result704// + ((m_parentSuite == null) ? 0 : m_parentSuite.hashCode());705 result = prime706 * result707 + ((m_skipFailedInvocationCounts == null) ? 0708 : m_skipFailedInvocationCounts.hashCode());709 result = prime * result710 + ((m_suiteFiles == null) ? 0 : m_suiteFiles.hashCode());711 result = prime * result + ((m_test == null) ? 0 : m_test.hashCode());712 result = prime * result + ((m_tests == null) ? 0 : m_tests.hashCode());713 result = prime * result + m_threadCount;714 result = prime * result715 + ((m_timeOut == null) ? 0 : m_timeOut.hashCode());716 result = prime * result717 + ((m_verbose == null) ? 0 : m_verbose.hashCode());718 result = prime * result719 + ((m_xmlPackages == null) ? 0 : m_xmlPackages.hashCode());720 return result;721 }722 /**723 * Used to debug equals() bugs.724 */725 static boolean f() {726 return false;727 }728 @Override729 public boolean equals(Object obj) {730 if (this == obj) {731 return true;732 }733 if (obj == null) {734 return f();735 }736 if (getClass() != obj.getClass()) {737 return f();738 }739 XmlSuite other = (XmlSuite) obj;740// if (m_childSuites == null) {741// if (other.m_childSuites != null)742// return f();743// } else if (!m_childSuites.equals(other.m_childSuites))744// return f();745 if (m_configFailurePolicy == null) {746 if (other.m_configFailurePolicy != null) {747 return f();748 }749 } else if (!m_configFailurePolicy.equals(other.m_configFailurePolicy)) {750 return f();751 }752 if (m_dataProviderThreadCount != other.m_dataProviderThreadCount) {753 return f();754 }755 if (m_expression == null) {756 if (other.m_expression != null) {757 return f();758 }759 } else if (!m_expression.equals(other.m_expression)) {760 return f();761 }762 if (m_isJUnit == null) {763 if (other.m_isJUnit != null) {764 return f();765 }766 } else if (!m_isJUnit.equals(other.m_isJUnit)) {767 return f();768 }769 if (m_listeners == null) {770 if (other.m_listeners != null) {771 return f();772 }773 } else if (!m_listeners.equals(other.m_listeners)) {774 return f();775 }776 if (m_methodSelectors == null) {777 if (other.m_methodSelectors != null) {778 return f();779 }780 } else if (!m_methodSelectors.equals(other.m_methodSelectors)) {781 return f();782 }783 if (m_name == null) {784 if (other.m_name != null) {785 return f();786 }787 } else if (!m_name.equals(other.m_name)) {788 return f();789 }790 if (m_objectFactory == null) {791 if (other.m_objectFactory != null) {792 return f();793 }794 } else if (!m_objectFactory.equals(other.m_objectFactory)) {795 return f();796 }797 if (m_parallel == null) {798 if (other.m_parallel != null) {799 return f();800 }801 } else if (!m_parallel.equals(other.m_parallel)) {802 return f();803 }804// if (m_parameters == null) {805// if (other.m_parameters != null) {806// return f();807// }808// } else if (!m_parameters.equals(other.m_parameters)) {809// return f();810// }811// if (m_parentSuite == null) {812// if (other.m_parentSuite != null)813// return f();814// } else if (!m_parentSuite.equals(other.m_parentSuite))815// return f();816 if (m_skipFailedInvocationCounts == null) {817 if (other.m_skipFailedInvocationCounts != null)818 return f();819 } else if (!m_skipFailedInvocationCounts820 .equals(other.m_skipFailedInvocationCounts))821 return f();822 if (m_suiteFiles == null) {823 if (other.m_suiteFiles != null)824 return f();825 } else if (!m_suiteFiles.equals(other.m_suiteFiles))826 return f();827 if (m_test == null) {828 if (other.m_test != null)829 return f();830 } else if (!m_test.equals(other.m_test))831 return f();832 if (m_tests == null) {833 if (other.m_tests != null)834 return f();835 } else if (!m_tests.equals(other.m_tests))836 return f();837 if (m_threadCount != other.m_threadCount)838 return f();839 if (m_timeOut == null) {840 if (other.m_timeOut != null)841 return f();842 } else if (!m_timeOut.equals(other.m_timeOut))843 return f();844 if (m_verbose == null) {845 if (other.m_verbose != null)846 return f();847 } else if (!m_verbose.equals(other.m_verbose))848 return f();849 if (m_xmlPackages == null) {850 if (other.m_xmlPackages != null)851 return f();852 } else if (!m_xmlPackages.equals(other.m_xmlPackages))853 return f();854 return true;855 }856 /**857 * @deprecated Use {@link #setPreserveOrder(Boolean)} instead858 */859 @Deprecated860 public void setPreserveOrder(String f) {861 setPreserveOrder(Boolean.valueOf(f));862 }863 public void setPreserveOrder(Boolean f) {864 m_preserveOrder = f;865 }866 public Boolean getPreserveOrder() {867 return m_preserveOrder;868 }869 /**870 * @return Returns the includedGroups.871 * Note: do not modify the returned value, use {@link #addIncludedGroup(String)}.872 */873 public List<String> getIncludedGroups() {874 if (m_parentSuite != null) {875 return m_parentSuite.getIncludedGroups();876 } else if (m_xmlGroups != null && (m_xmlGroups.getRun() != null)) {877 return m_xmlGroups.getRun().getIncludes();878 } else {879 // deprecated880 return m_includedGroups;881 }882 }883 public void addIncludedGroup(String g) {884 m_includedGroups.add(g);885 }886 /**887 * @param g - The list of groups to include.888 */889 public void setIncludedGroups(List<String> g) {890 m_includedGroups = g;891 }892 /**893 * @param g The excludedGrousps to set.894 */895 public void setExcludedGroups(List<String> g) {896 m_excludedGroups = g;897 }898 /**899 * @return Returns the excludedGroups.900 * Note: do not modify the returned value, use {@link #addExcludedGroup(String)}.901 */902 public List<String> getExcludedGroups() {903 if (m_parentSuite != null) {904 return m_parentSuite.getExcludedGroups();905 } else if (m_xmlGroups != null && (m_xmlGroups.getRun() != null)) {906 return m_xmlGroups.getRun().getExcludes();907 } else {908 return m_excludedGroups;909 }910 }911 public void addExcludedGroup(String g) {912 m_excludedGroups.add(g);913 }914 public Boolean getGroupByInstances() {915 return m_groupByInstances;916 }917 public void setGroupByInstances(boolean f) {918 m_groupByInstances = f;919 }920 public void addListener(String listener) {921 m_listeners.add(listener);922 }923 public Boolean getAllowReturnValues() {924 return m_allowReturnValues;925 }926 public void setAllowReturnValues(Boolean allowReturnValues) {927 m_allowReturnValues = allowReturnValues;928 }...
Source:XmlTest.java
...214 } else {215 return 1;216 }217 }218 public boolean getGroupByInstances() {219 Boolean result = m_groupByInstances;220 if (result == null || XmlSuite.DEFAULT_GROUP_BY_INSTANCES.equals(m_groupByInstances)) {221 result = m_suite.getGroupByInstances();222 }223 if (result != null) {224 return result;225 } else {226 return XmlSuite.DEFAULT_GROUP_BY_INSTANCES;227 }228 }229 public void setGroupByInstances(boolean f) {230 m_groupByInstances = f;231 }232 /**233 * @return Returns the isJUnit.234 */235 public boolean isJUnit() {236 Boolean result = m_isJUnit;237 if (null == result || XmlSuite.DEFAULT_JUNIT.equals(result)) {238 result = m_suite.isJUnit();239 }240 return result;241 }242 /**243 * @param isJUnit The isJUnit to set.244 */245 public void setJUnit(boolean isJUnit) {246 m_isJUnit = isJUnit;247 }248 // For YAML249 public void setJunit(boolean isJUnit) {250 setJUnit(isJUnit);251 }252 public void setSkipFailedInvocationCounts(boolean skip) {253 m_skipFailedInvocationCounts = skip;254 }255 /**256 * @return Returns the isJUnit.257 */258 public boolean skipFailedInvocationCounts() {259 Boolean result = m_skipFailedInvocationCounts;260 if (null == result) {261 result = m_suite.skipFailedInvocationCounts();262 }263 return result;264 }265 public void addMetaGroup(String name, List<String> metaGroup) {266 if (m_xmlGroups == null) {267 m_xmlGroups = new XmlGroups();268 }269 XmlDefine define = new XmlDefine();270 define.setName(name);271 define.getIncludes().addAll(metaGroup);272 m_xmlGroups.getDefines().add(define);273 }274 public void addMetaGroup(String name, String... metaGroup) {275 addMetaGroup(name, Arrays.asList(metaGroup));276 }277 // For YAML278 public void setMetaGroups(Map<String, List<String>> metaGroups) {279 for (Map.Entry<String, List<String>> entry : metaGroups.entrySet()) {280 addMetaGroup(entry.getKey(), entry.getValue());281 }282 }283 /**284 * @return Returns the metaGroups.285 */286 public Map<String, List<String>> getMetaGroups() {287 if (m_xmlGroups == null) {288 return Collections.emptyMap();289 }290 Map<String, List<String>> result = Maps.newHashMap();291 List<XmlDefine> defines = m_xmlGroups.getDefines();292 for (XmlDefine xd : defines) {293 result.put(xd.getName(), xd.getIncludes());294 }295 return result;296 }297 /**298 * @param parameters299 */300 public void setParameters(Map<String, String> parameters) {301 m_parameters = parameters;302 }303 public void addParameter(String key, String value) {304 m_parameters.put(key, value);305 }306 public String getParameter(String name) {307 String result = m_parameters.get(name);308 if (null == result) {309 result = m_suite.getParameter(name);310 }311 return result;312 }313 /**314 * @return the parameters defined in this test tag and the tags above it.315 */316 public Map<String, String> getAllParameters() {317 Map<String, String> result = Maps.newHashMap();318 result.putAll(getSuite().getParameters());319 result.putAll(m_parameters);320 return result;321 }322 /**323 * @return the parameters defined in this tag, and only this test tag. To retrieve324 * the inherited parameters as well, call {@code getAllParameters()}.325 */326 public Map<String, String> getLocalParameters() {327 return m_parameters;328 }329 /**330 * @deprecated Use {@code getLocalParameters()} or {@code getAllParameters()}331 */332 @Deprecated333 public Map<String, String> getParameters() {334 return getAllParameters();335 }336 /**337 * @deprecated Use {@code getLocalParameters()} instead338 *339 * @return the parameters defined on this <test> tag only340 */341 @Deprecated342 public Map<String, String> getTestParameters() {343 return getLocalParameters();344 }345 public void setParallel(XmlSuite.ParallelMode parallel) {346 m_parallel = skipDeprecatedValues(parallel);347 }348 public XmlSuite.ParallelMode getParallel() {349 XmlSuite.ParallelMode result;350 if (null != m_parallel || XmlSuite.DEFAULT_PARALLEL.equals(m_parallel)) {351 result = m_parallel;352 }353 else {354 result = m_suite.getParallel();355 }356 return result;357 }358 public String getTimeOut() {359 String result = null;360 if (null != m_timeOut) {361 result = m_timeOut;362 }363 else {364 result = m_suite.getTimeOut();365 }366 return result;367 }368 public long getTimeOut(long def) {369 long result = def;370 if (getTimeOut() != null) {371 result = Long.parseLong(getTimeOut());372 }373 return result;374 }375 public void setTimeOut(long timeOut) {376 m_timeOut = Long.toString(timeOut);377 }378 private void setTimeOut(String timeOut) {379 m_timeOut = timeOut;380 }381 public void setExpression(String expression) {382 setBeanShellExpression(expression);383 }384 public void setBeanShellExpression(String expression) {385 List<XmlMethodSelector> selectors = getMethodSelectors();386 if (selectors.size() > 0) {387 selectors.get(0).setExpression(expression);388 } else if (expression != null) {389 XmlMethodSelector xms = new XmlMethodSelector();390 xms.setExpression(expression);391 xms.setLanguage("BeanShell");392 getMethodSelectors().add(xms);393 }394 }395 public String getExpression() {396 List<XmlMethodSelector> selectors = getMethodSelectors();397 if (selectors.size() > 0) {398 return selectors.get(0).getExpression();399 } else {400 return null;401 }402 }403 public String toXml(String indent) {404 XMLStringBuffer xsb = new XMLStringBuffer(indent);405 Properties p = new Properties();406 p.setProperty("name", getName());407 if (m_isJUnit != null) {408 XmlUtils.setProperty(p, "junit", m_isJUnit.toString(), XmlSuite.DEFAULT_JUNIT.toString());409 }410 if (m_parallel != null) {411 XmlUtils.setProperty(p, "parallel", m_parallel.toString(), XmlSuite.DEFAULT_PARALLEL.toString());412 }413 if (m_verbose != null) {414 XmlUtils.setProperty(p, "verbose", m_verbose.toString(), XmlSuite.DEFAULT_VERBOSE.toString());415 }416 if (null != m_timeOut) {417 p.setProperty("time-out", m_timeOut.toString());418 }419 if (m_preserveOrder != null && ! XmlSuite.DEFAULT_PRESERVE_ORDER.equals(m_preserveOrder)) {420 p.setProperty("preserve-order", m_preserveOrder.toString());421 }422 if (m_threadCount != -1) {423 p.setProperty("thread-count", Integer.toString(m_threadCount));424 }425 if (m_groupByInstances != null) {426 XmlUtils.setProperty(p, "group-by-instances", String.valueOf(getGroupByInstances()),427 XmlSuite.DEFAULT_GROUP_BY_INSTANCES.toString());428 }429 xsb.push("test", p);430 if (null != getMethodSelectors() && !getMethodSelectors().isEmpty()) {431 xsb.push("method-selectors");432 for (XmlMethodSelector selector: getMethodSelectors()) {433 xsb.getStringBuffer().append(selector.toXml(indent + " "));434 }435 xsb.pop("method-selectors");436 }437 XmlUtils.dumpParameters(xsb, m_parameters);438 // groups439 if ((m_xmlGroups != null &&440 (!m_xmlGroups.getDefines().isEmpty() ||...
Source:TestNGTestClassProcessor.java
...102 Class<?> configFailurePolicyArgType = getConfigFailurePolicyArgType(testNg);103 Object configFailurePolicyArgValue = getConfigFailurePolicyArgValue(testNg);104 invokeVerifiedMethod(testNg, "setConfigFailurePolicy", configFailurePolicyArgType, configFailurePolicyArgValue, DEFAULT_CONFIG_FAILURE_POLICY);105 invokeVerifiedMethod(testNg, "setPreserveOrder", boolean.class, options.getPreserveOrder(), false);106 invokeVerifiedMethod(testNg, "setGroupByInstances", boolean.class, options.getGroupByInstances(), false);107 testNg.setUseDefaultListeners(options.getUseDefaultListeners());108 testNg.setVerbose(0);109 testNg.setGroups(CollectionUtils.join(",", options.getIncludeGroups()));110 testNg.setExcludedGroups(CollectionUtils.join(",", options.getExcludeGroups()));111 //adding custom test listeners before Gradle's listeners.112 //this way, custom listeners are more powerful and, for example, they can change test status.113 for (String listenerClass : options.getListeners()) {114 try {115 testNg.addListener(JavaReflectionUtil.newInstance(applicationClassLoader.loadClass(listenerClass)));116 } catch (Throwable e) {117 throw new GradleException(String.format("Could not add a test listener with class '%s'.", listenerClass), e);118 }119 }120 if (!options.getIncludedTests().isEmpty() || !options.getIncludedTestsCommandLine().isEmpty() || !options.getExcludedTests().isEmpty()) {...
Source:DefaultXmlWeaver.java
...35 }36 XmlUtils.setProperty(37 p,38 "group-by-instances",39 String.valueOf(xmlSuite.getGroupByInstances()),40 DEFAULT_GROUP_BY_INSTANCES.toString());41 XmlUtils.setProperty(42 p,43 "configfailurepolicy",44 xmlSuite.getConfigFailurePolicy().toString(),45 DEFAULT_CONFIG_FAILURE_POLICY.toString());46 XmlUtils.setProperty(47 p,48 "thread-count",49 String.valueOf(xmlSuite.getThreadCount()),50 DEFAULT_THREAD_COUNT.toString());51 XmlUtils.setProperty(52 p,53 "data-provider-thread-count",54 String.valueOf(xmlSuite.getDataProviderThreadCount()),55 DEFAULT_DATA_PROVIDER_THREAD_COUNT.toString());56 if (isStringNotEmpty(xmlSuite.getTimeOut())) {57 p.setProperty("time-out", xmlSuite.getTimeOut());58 }59 if (!DEFAULT_JUNIT.equals(xmlSuite.isJUnit())) {60 p.setProperty(61 "junit",62 xmlSuite.isJUnit() != null ? xmlSuite.isJUnit().toString() : "false"); // TESTNG-14163 }64 XmlUtils.setProperty(65 p,66 "skipfailedinvocationcounts",67 xmlSuite.skipFailedInvocationCounts().toString(),68 DEFAULT_SKIP_FAILED_INVOCATION_COUNTS.toString());69 if (null != xmlSuite.getObjectFactory()) {70 p.setProperty("object-factory", xmlSuite.getObjectFactory().getClass().getName());71 }72 if (isStringNotEmpty(xmlSuite.getParentModule())) {73 p.setProperty("parent-module", xmlSuite.getParentModule());74 }75 if (isStringNotEmpty(xmlSuite.getGuiceStage())) {76 p.setProperty("guice-stage", xmlSuite.getGuiceStage());77 }78 XmlUtils.setProperty(79 p,80 "allow-return-values",81 String.valueOf(xmlSuite.getAllowReturnValues()),82 DEFAULT_ALLOW_RETURN_VALUES.toString());83 xsb.push("suite", p);84 XmlUtils.dumpParameters(xsb, xmlSuite.getParameters());85 if (hasElements(xmlSuite.getListeners())) {86 xsb.push("listeners");87 for (String listenerName : xmlSuite.getLocalListeners()) {88 Properties listenerProps = new Properties();89 listenerProps.setProperty("class-name", listenerName);90 xsb.addEmptyElement("listener", listenerProps);91 }92 xsb.pop("listeners");93 }94 if (hasElements(xmlSuite.getXmlPackages())) {95 xsb.push("packages");96 for (XmlPackage pack : xmlSuite.getXmlPackages()) {97 xsb.getStringBuffer().append(pack.toXml(" "));98 }99 xsb.pop("packages");100 }101 if (xmlSuite.getXmlMethodSelectors() != null) {102 xsb.getStringBuffer().append(xmlSuite.getXmlMethodSelectors().toXml(" "));103 } else {104 // deprecated105 if (hasElements(xmlSuite.getMethodSelectors())) {106 xsb.push("method-selectors");107 for (XmlMethodSelector selector : xmlSuite.getMethodSelectors()) {108 xsb.getStringBuffer().append(selector.toXml(" "));109 }110 xsb.pop("method-selectors");111 }112 }113 List<String> suiteFiles = xmlSuite.getSuiteFiles();114 if (!suiteFiles.isEmpty()) {115 xsb.push("suite-files");116 for (String sf : suiteFiles) {117 Properties prop = new Properties();118 prop.setProperty("path", sf);119 xsb.addEmptyElement("suite-file", prop);120 }121 xsb.pop("suite-files");122 }123 List<String> included = xmlSuite.getIncludedGroups();124 List<String> excluded = xmlSuite.getExcludedGroups();125 if (hasElements(included) || hasElements(excluded)) {126 xsb.push("groups");127 xsb.push("run");128 for (String g : included) {129 xsb.addEmptyElement("include", "name", g);130 }131 for (String g : excluded) {132 xsb.addEmptyElement("exclude", "name", g);133 }134 xsb.pop("run");135 xsb.pop("groups");136 }137 if (xmlSuite.getGroups() != null) {138 xsb.getStringBuffer().append(xmlSuite.getGroups().toXml(" "));139 }140 for (XmlTest test : xmlSuite.getTests()) {141 xsb.getStringBuffer().append(test.toXml(" "));142 }143 xsb.pop("suite");144 return xsb.toXML();145 }146 @Override147 public String asXml(XmlTest xmlTest, String indent) {148 XMLStringBuffer xsb = new XMLStringBuffer(indent);149 xsb.setDefaultComment(defaultComment);150 Properties p = new Properties();151 p.setProperty("name", xmlTest.getName());152 XmlUtils.setProperty(153 p, "junit", Boolean.toString(xmlTest.isJUnit()), XmlSuite.DEFAULT_JUNIT.toString());154 XmlUtils.setProperty(155 p, "parallel", xmlTest.getParallel().toString(), XmlSuite.DEFAULT_PARALLEL.toString());156 XmlUtils.setProperty(157 p, "verbose", Integer.toString(xmlTest.getVerbose()), XmlSuite.DEFAULT_VERBOSE.toString());158 if (null != xmlTest.getTimeOut()) {159 p.setProperty("time-out", xmlTest.getTimeOut());160 }161 if (xmlTest.getPreserveOrder() != null162 && !XmlSuite.DEFAULT_PRESERVE_ORDER.equals(xmlTest.getPreserveOrder())) {163 p.setProperty("preserve-order", xmlTest.getPreserveOrder().toString());164 }165 if (xmlTest.getThreadCount() != -1) {166 p.setProperty("thread-count", Integer.toString(xmlTest.getThreadCount()));167 }168 XmlUtils.setProperty(169 p,170 "group-by-instances",171 String.valueOf(xmlTest.getGroupByInstances()),172 XmlSuite.DEFAULT_GROUP_BY_INSTANCES.toString());173 xsb.push("test", p);174 if (null != xmlTest.getMethodSelectors() && !xmlTest.getMethodSelectors().isEmpty()) {175 xsb.push("method-selectors");176 for (XmlMethodSelector selector : xmlTest.getMethodSelectors()) {177 xsb.getStringBuffer().append(selector.toXml(indent + " "));178 }179 xsb.pop("method-selectors");180 }181 XmlUtils.dumpParameters(xsb, xmlTest.getLocalParameters());182 // groups183 if ((xmlTest.getXmlGroups() != null184 && (!xmlTest.getXmlGroups().getDefines().isEmpty()185 || (xmlTest.getXmlGroups().getRun() != null...
Source:DynamicGraphHelper.java
...89 private static Comparator<XmlClass> classComparator() {90 return Comparator.comparingInt(XmlClass::getIndex);91 }92 private static boolean canGroupByInstances(XmlTest xmlTest) {93 return xmlTest.getGroupByInstances() && ! xmlTest.getParallel().equals(ParallelMode.INSTANCES);94 }95 private static ListMultiMap<ITestNGMethod, ITestNGMethod> createClassDependencies(96 ITestNGMethod[] methods, XmlTest test) {97 Map<String, List<ITestNGMethod>> classes = Maps.newHashMap();98 // Note: use a List here to preserve the ordering but make sure99 // we don't add the same class twice100 List<XmlClass> sortedClasses = Lists.newArrayList();101 for (XmlClass c : test.getXmlClasses()) {102 classes.put(c.getName(), new ArrayList<>());103 if (!sortedClasses.contains(c)) {104 sortedClasses.add(c);105 }106 }107 // Sort the classes based on their order of appearance in the XML...
Source:AlterSuiteListener.java
...35 ReportManager.log("getPreserveOrder: " + suite.getPreserveOrder());36 ReportManager.log("getDataProviderThreadCount: " + suite.getDataProviderThreadCount());37 ReportManager.log("getThreadCount: " + suite.getThreadCount());38 ReportManager.log("getVerbose: " + suite.getVerbose());39 ReportManager.log("getGroupByInstances: " + suite.getGroupByInstances());40 ReportManager.log("getParallel: " + suite.getParallel());41 }42 });43 }4445 private void renameDefaultSuiteAndTest(List<XmlSuite> suites) {46 String prefix = "SHAFT_Engine: ";47 // rename default suite and test48 suites.forEach(suite -> {49 if (suite.getName().trim().equalsIgnoreCase("default suite")50 || suite.getName().trim().equalsIgnoreCase("surefire suite")) {51 suite.setName(prefix + "Custom Suite");52 } else {53 suite.setName(prefix + suite.getName());
...
getGroupByInstances
Using AI Code Generation
1XmlSuite suite = new XmlSuite();2suite.setName("Suite");3XmlTest test = new XmlTest(suite);4test.setName("Test");5test.setXmlClasses(Collections.singletonList(new XmlClass("com.example.TestClass")));6test.setGroups(Collections.singletonList("group1"));7test.setGroupByInstances(true);8List<XmlSuite> suites = new ArrayList<>();9suites.add(suite);10TestNG tng = new TestNG();11tng.setXmlSuites(suites);12tng.run();13package com.example; import org.testng.annotations.Test; public class TestClass { @Test public void testMethod1() { System.out.println("PASSED: testMethod1"); } @Test public void testMethod2() { System.out.println("PASSED: testMethod2"); } }14package com.example; import org.testng.annotations.Test; public class TestClass { @Test(groups = "group1") public void testMethod1() { System.out.println("PASSED: testMethod1"); } @Test(groups = "group2") public void testMethod2() { System.out.println("PASSED: testMethod2"); } }15package com.example; import org.testng.annotations.Test; public class TestClass { @Test(groups = "group1") public void testMethod1() { System.out.println("PASSED: testMethod1"); } @Test(groups = "group2") public void testMethod2() { System.out.println("PASSED: testMethod2"); } }16package com.example; import org.testng.annotations.Test; public class TestClass { @Test(groups = "group1") public void testMethod1() { System.out.println("PASSED: testMethod1"); } @Test(groups = "group2") public void testMethod2() { System.out.println("PASSED: testMethod2"); } }17package com.example; import org.testng.annotations.Test; public class TestClass { @
getGroupByInstances
Using AI Code Generation
1XmlSuite suite = new XmlSuite();2suite.setParallel(XmlSuite.ParallelMode.METHODS);3suite.setGroupByInstances(true);4suite.setThreadCount(3);5suite.setName("ParallelMethodTest");6XmlTest test = new XmlTest(suite);7test.setName("ParallelMethodTest");8test.setPreserveOrder(true);9test.setParallel(XmlSuite.ParallelMode.METHODS);10test.setThreadCount(3);11Map<String, String> parameters = new HashMap<>();12parameters.put("browser", "chrome");13test.setParameters(parameters);14XmlClass xmlClass = new XmlClass("com.test.Test1");15test.setXmlClasses(Collections.singletonList(xmlClass));16List<XmlSuite> suites = new ArrayList<>();17suites.add(suite);18TestNG tng = new TestNG();19tng.setXmlSuites(suites);20tng.run();
getGroupByInstances
Using AI Code Generation
1package com.test;2import java.util.List;3import java.util.Map;4import java.util.Set;5import org.testng.xml.XmlSuite;6import org.testng.xml.XmlTest;7public class GetGroupsFromTestNGXML {8 public static void main(String[] args) {9 XmlSuite xmlSuite = new XmlSuite();10 xmlSuite.setName("testng");11 xmlSuite.setFileName("testng.xml");12 xmlSuite.setParallel(XmlSuite.ParallelMode.TESTS);13 xmlSuite.setThreadCount(2);14 xmlSuite.setVerbose(2);15 xmlSuite.setPreserveOrder(true);16 XmlTest xmlTest1 = new XmlTest(xmlSuite);17 xmlTest1.setName("Test1");18 xmlTest1.addParameter("browser", "firefox");19 xmlTest1.addParameter("env", "qa");20 xmlTest1.setPreserveOrder(true);21 xmlTest1.setParallel(XmlSuite.ParallelMode.TESTS);22 xmlTest1.setThreadCount(2);23 xmlTest1.setVerbose(2);24 xmlTest1.setGroups("smoke");25 XmlTest xmlTest2 = new XmlTest(xmlSuite);26 xmlTest2.setName("Test2");27 xmlTest2.addParameter("browser", "chrome");28 xmlTest2.addParameter("env", "qa");29 xmlTest2.setPreserveOrder(true);30 xmlTest2.setParallel(XmlSuite.ParallelMode.TESTS);31 xmlTest2.setThreadCount(2);32 xmlTest2.setVerbose(2);33 xmlTest2.setGroups("smoke");34 XmlTest xmlTest3 = new XmlTest(xmlSuite);35 xmlTest3.setName("Test3");36 xmlTest3.addParameter("browser", "ie");37 xmlTest3.addParameter("env", "qa");38 xmlTest3.setPreserveOrder(true);39 xmlTest3.setParallel(XmlSuite.ParallelMode.TESTS);40 xmlTest3.setThreadCount(2);41 xmlTest3.setVerbose(2);42 xmlTest3.setGroups("smoke");43 XmlTest xmlTest4 = new XmlTest(xmlSuite);44 xmlTest4.setName("Test4");45 xmlTest4.addParameter("browser", "firefox");46 xmlTest4.addParameter("env", "qa");47 xmlTest4.setPreserveOrder(true);48 xmlTest4.setParallel(XmlSuite.Parallel
TestNG is a Java-based open-source framework for test automation that includes various test types, such as unit testing, functional testing, E2E testing, etc. TestNG is in many ways similar to JUnit and NUnit. But in contrast to its competitors, its extensive features make it a lot more reliable framework. One of the major reasons for its popularity is its ability to structure tests and improve the scripts' readability and maintainability. Another reason can be the important characteristics like the convenience of using multiple annotations, reliance, and priority that make this framework popular among developers and testers for test design. You can refer to the TestNG tutorial to learn why you should choose the TestNG framework.
You can push your abilities to do automated testing using TestNG and advance your career by earning a TestNG certification. Check out our TestNG certification.
Watch this complete tutorial to learn how you can leverage the capabilities of the TestNG framework for Selenium automation testing.
Get 100 minutes of automation test minutes FREE!!