How to use isJUnit method of org.testng.xml.XmlSuite class

Best Testng code snippet using org.testng.xml.XmlSuite.isJUnit

Source:XmlTest.java Github

copy

Full Screen

...22 public static final int DEFAULT_TIMEOUT_MS = Integer.MAX_VALUE;23 private XmlSuite m_suite;24 private String m_name;25 private Integer m_verbose = XmlSuite.DEFAULT_VERBOSE;26 private Boolean m_isJUnit = XmlSuite.DEFAULT_JUNIT;27 private int m_threadCount= -1;28 private List<XmlClass> m_xmlClasses = Lists.newArrayList();29 private Map<String, String> m_parameters = Maps.newHashMap();30 private XmlSuite.ParallelMode m_parallel;31 private List<XmlMethodSelector> m_methodSelectors = Lists.newArrayList();32 // test level packages33 private List<XmlPackage> m_xmlPackages = Lists.newArrayList();34 private String m_timeOut;35 private Boolean m_skipFailedInvocationCounts = XmlSuite.DEFAULT_SKIP_FAILED_INVOCATION_COUNTS;36 private Map<String, List<Integer>> m_failedInvocationNumbers = null; // lazily initialized37 private Boolean m_preserveOrder = XmlSuite.DEFAULT_PRESERVE_ORDER;38 private int m_index;39 private Boolean m_groupByInstances;40 private Boolean m_allowReturnValues = null;41 private Map<String, String> m_xmlDependencyGroups = Maps.newHashMap();42 /**43 * Constructs a <code>XmlTest</code> and adds it to suite's list of tests.44 *45 * @param suite the parent suite.46 * @param index the index of this test tag in testng.xml47 */48 public XmlTest(XmlSuite suite, int index) {49 init(suite, index);50 }51 public XmlTest(XmlSuite suite) {52 init(suite, 0);53 }54 private void init(XmlSuite suite, int index) {55 m_suite = suite;56 m_suite.getTests().add(this);57 m_index = index;58 //no two tests in the same suite should have the same name.59 //so, make the default test name unique60 m_name = TestNG.DEFAULT_COMMAND_LINE_TEST_NAME61 + " " + UUID.randomUUID().toString();62 }63 // For YAML64 public XmlTest() {65 }66 public void setXmlPackages(List<XmlPackage> packages) {67 m_xmlPackages = Lists.newArrayList(packages);68 }69 public List<XmlPackage> getXmlPackages() {70 return m_xmlPackages;71 }72 // For YAML73 public List<XmlPackage> getPackages() {74 return getXmlPackages();75 }76 // For YAML77 public void setPackages(List<XmlPackage> p) {78 setXmlPackages(p);79 }80 public List<XmlMethodSelector> getMethodSelectors() {81 return m_methodSelectors;82 }83 public void setMethodSelectors(List<XmlMethodSelector> methodSelectors) {84 m_methodSelectors = Lists.newArrayList(methodSelectors);85 }86 /**87 * Returns the suite this test is part of.88 * @return the suite this test is part of.89 */90 public XmlSuite getSuite() {91 return m_suite;92 }93 /**94 * @return the includedGroups.95 */96 public List<String> getIncludedGroups() {97 List<String> result = Lists.newArrayList();98 if (m_xmlGroups != null && m_xmlGroups.getRun() != null) {99 result.addAll(m_xmlGroups.getRun().getIncludes());100 }101 result.addAll(m_suite.getIncludedGroups());102 return Collections.unmodifiableList(result);103 }104 /**105 * Sets the XML Classes.106 * @param classes The classes to set.107 * @deprecated use setXmlClasses108 */109 @Deprecated110 public void setClassNames(List<XmlClass> classes) {111 m_xmlClasses = classes;112 }113 /**114 * @return Returns the classes.115 */116 public List<XmlClass> getXmlClasses() {117 return m_xmlClasses;118 }119 // For YAML120 public List<XmlClass> getClasses() {121 return getXmlClasses();122 }123 // For YAML124 public void setClasses(List<XmlClass> c) {125 setXmlClasses(c);126 }127 /**128 * Sets the XML Classes.129 * @param classes The classes to set.130 */131 public void setXmlClasses(List<XmlClass> classes) {132 m_xmlClasses = classes;133 }134 /**135 * @return Returns the name.136 */137 public String getName() {138 return m_name;139 }140 /**141 * @param name The name to set.142 */143 public void setName(String name) {144 m_name = name;145 }146 /**147 * @param v148 */149 public void setVerbose(int v) {150 m_verbose = v;151 }152 public int getThreadCount() {153 return m_threadCount > 0 ? m_threadCount : getSuite().getThreadCount();154 }155 public void setThreadCount(int threadCount) {156 m_threadCount = threadCount;157 }158 public void setIncludedGroups(List<String> g) {159 if (m_xmlGroups == null) {160 m_xmlGroups = new XmlGroups();161 }162 if (m_xmlGroups.getRun() == null) {163 m_xmlGroups.setRun(new XmlRun());164 }165 List<String> includes = m_xmlGroups.getRun().getIncludes();166 includes.clear();167 includes.addAll(g);168 }169 public void setExcludedGroups(List<String> g) {170 if (m_xmlGroups == null) {171 m_xmlGroups = new XmlGroups();172 }173 if (m_xmlGroups.getRun() == null) {174 m_xmlGroups.setRun(new XmlRun());175 }176 List<String> excludes = m_xmlGroups.getRun().getExcludes();177 excludes.clear();178 excludes.addAll(g);179 }180 public List<String> getExcludedGroups() {181 List<String> result = new ArrayList<>();182 if (m_xmlGroups != null && m_xmlGroups.getRun() != null) {183 result.addAll(m_xmlGroups.getRun().getExcludes());184 }185 result.addAll(m_suite.getExcludedGroups());186 return Collections.unmodifiableList(result);187 }188 public void addIncludedGroup(String g) {189 if (m_xmlGroups == null) {190 m_xmlGroups = new XmlGroups();191 m_xmlGroups.setRun(new XmlRun());192 }193 m_xmlGroups.getRun().getIncludes().add(g);194 }195 public void addExcludedGroup(String g) {196 if (m_xmlGroups == null) {197 m_xmlGroups = new XmlGroups();198 }199 if (m_xmlGroups.getRun() == null) {200 m_xmlGroups.setRun(new XmlRun());201 }202 m_xmlGroups.getRun().getExcludes().add(g);203 }204 /**205 * @return Returns the verbose.206 */207 public int getVerbose() {208 Integer result = m_verbose;209 if (null == result || XmlSuite.DEFAULT_VERBOSE.equals(m_verbose)) {210 result = m_suite.getVerbose();211 }212 if (null != result) {213 return result;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() ||441 (m_xmlGroups.getRun() != null && (!m_xmlGroups.getRun().getIncludes().isEmpty() || !m_xmlGroups.getRun().getExcludes().isEmpty()))442 )443 ) || !m_xmlDependencyGroups.isEmpty()) {444 xsb.push("groups");445 // define446 if (m_xmlGroups != null) {447 for (XmlDefine define : m_xmlGroups.getDefines()) {448 Properties metaGroupProp = new Properties();449 metaGroupProp.setProperty("name", define.getName());450 xsb.push("define", metaGroupProp);451 for (String groupName : define.getIncludes()) {452 Properties includeProps = new Properties();453 includeProps.setProperty("name", groupName);454 xsb.addEmptyElement("include", includeProps);455 }456 xsb.pop("define");457 }458 }459 // run460 if ((m_xmlGroups != null && m_xmlGroups.getRun() != null) && (!m_xmlGroups.getRun().getIncludes().isEmpty() || !m_xmlGroups.getRun().getExcludes().isEmpty())) {461 xsb.push("run");462 for (String includeGroupName: m_xmlGroups.getRun().getIncludes()) {463 Properties includeProps = new Properties();464 includeProps.setProperty("name", includeGroupName);465 xsb.addEmptyElement("include", includeProps);466 }467 for (String excludeGroupName : m_xmlGroups.getRun().getExcludes()) {468 Properties excludeProps = new Properties();469 excludeProps.setProperty("name", excludeGroupName);470 xsb.addEmptyElement("exclude", excludeProps);471 }472 xsb.pop("run");473 }474 // group dependencies475 if (m_xmlDependencyGroups != null && ! m_xmlDependencyGroups.isEmpty()) {476 xsb.push("dependencies");477 for (Map.Entry<String, String> entry : m_xmlDependencyGroups.entrySet()) {478 xsb.addEmptyElement("group", "name", entry.getKey(), "depends-on", entry.getValue());479 }480 xsb.pop("dependencies");481 }482 xsb.pop("groups");483 }484 if (null != m_xmlPackages && !m_xmlPackages.isEmpty()) {485 xsb.push("packages");486 for (XmlPackage pack: m_xmlPackages) {487 xsb.getStringBuffer().append(pack.toXml(" "));488 }489 xsb.pop("packages");490 }491 // classes492 if (null != getXmlClasses() && !getXmlClasses().isEmpty()) {493 xsb.push("classes");494 for (XmlClass cls : getXmlClasses()) {495 xsb.getStringBuffer().append(cls.toXml(indent + " "));496 }497 xsb.pop("classes");498 }499 xsb.pop("test");500 return xsb.toXML();501 }502 @Override503 public String toString() {504 StringBuilder result = new StringBuilder("[Test: \"")505 .append(m_name)506 .append("\"")507 .append(" verbose:")508 .append(m_verbose);509 result.append("[parameters:");510 for (Map.Entry<String, String> entry : m_parameters.entrySet()) {511 result.append(entry.getKey()).append("=>").append(entry.getValue()).append(",");512 }513 result.append("]");514 result.append("[metagroups:");515 if (m_xmlGroups != null) {516 for (XmlDefine define : m_xmlGroups.getDefines()) {517 result.append(define.getName()).append("=");518 for (String n : define.getIncludes()) {519 result.append(n).append(",");520 }521 }522 }523 result.append("] ");524 result.append("[included: ");525 if (m_xmlGroups != null && m_xmlGroups.getRun() != null) {526 for (String g : m_xmlGroups.getRun().getIncludes()) {527 result.append(g).append(" ");528 }529 }530 result.append("]");531 result.append("[excluded: ");532 if (m_xmlGroups != null && m_xmlGroups.getRun() != null) {533 for (String g : m_xmlGroups.getRun().getExcludes()) {534 result.append(g).append(" ");535 }536 }537 result.append("] ");538 result.append(" classes:");539 for (XmlClass cl : m_xmlClasses) {540 result.append(cl).append(" ");541 }542 result.append(" packages:");543 for (XmlPackage p : m_xmlPackages) {544 result.append(p).append(" ");545 }546 result.append("] ");547 return result.toString();548 }549 static void ppp(String s) {550 System.out.println("[XmlTest] " + s);551 }552 /**553 * Clone the <TT>source</TT> <CODE>XmlTest</CODE> by including:554 * - test attributes555 * - groups definitions556 * - parameters557 *558 * The &lt;classes&gt; sub element is ignored for the moment.559 *560 * @return a clone of the current XmlTest561 */562 @Override563 public Object clone() {564 XmlTest result = new XmlTest(getSuite());565 result.setName(getName());566 result.setIncludedGroups(getIncludedGroups());567 result.setExcludedGroups(getExcludedGroups());568 result.setJUnit(isJUnit());569 result.setParallel(getParallel());570 result.setVerbose(getVerbose());571 result.setParameters(getLocalParameters());572 result.setXmlPackages(getXmlPackages());573 result.setTimeOut(getTimeOut());574 Map<String, List<String>> metagroups = getMetaGroups();575 for (Map.Entry<String, List<String>> group: metagroups.entrySet()) {576 result.addMetaGroup(group.getKey(), group.getValue());577 }578 return result;579 }580 /**581 * Convenience method to cache the ordering numbers for methods.582 */583 public List<Integer> getInvocationNumbers(String method) {584 if (m_failedInvocationNumbers == null) {585 m_failedInvocationNumbers = Maps.newHashMap();586 for (XmlClass c : getXmlClasses()) {587 for (XmlInclude xi : c.getIncludedMethods()) {588 List<Integer> invocationNumbers = xi.getInvocationNumbers();589 if (invocationNumbers.size() > 0) {590 String methodName = c.getName() + "." + xi.getName();591 m_failedInvocationNumbers.put(methodName, invocationNumbers);592 }593 }594 }595 }596 List<Integer> result = m_failedInvocationNumbers.get(method);597 if (result == null) {598 // Don't use emptyList here since this list might end up receiving values if599 // the test run fails.600 return Lists.newArrayList();601 } else {602 return result;603 }604 }605 /**606 * @deprecated Use {@link #setPreserveOrder(Boolean)} instead607 */608 @Deprecated609 public void setPreserveOrder(String preserveOrder) {610 setPreserveOrder(Boolean.valueOf(preserveOrder));611 }612 public void setPreserveOrder(Boolean preserveOrder) {613 m_preserveOrder = preserveOrder;614 }615 public Boolean getPreserveOrder() {616 if (m_preserveOrder == null) {617 return m_suite.getPreserveOrder();618 }619 return m_preserveOrder;620 }621 public void setSuite(XmlSuite result) {622 m_suite = result;623 }624 public Boolean getAllowReturnValues() {625 if (m_allowReturnValues != null) return m_allowReturnValues;626 else return getSuite().getAllowReturnValues();627 }628 public void setAllowReturnValues(Boolean allowReturnValues) {629 m_allowReturnValues = allowReturnValues;630 }631 /**632 * Note that this attribute does not come from the XML file, it's calculated633 * internally and represents the order in which this test tag was found in its634 * &lt;suite&gt; tag. It's used to calculate the ordering of the tests635 * when preserve-test-order is true.636 */637 public int getIndex() {638 return m_index;639 }640 @Override641 public int hashCode() {642 final int prime = 31;643 int result = 1;644 result = prime * result645 + ((m_xmlGroups == null || m_xmlGroups.getRun() == null) ? 0 : m_xmlGroups.getRun().getExcludes().hashCode());646 result = prime647 * result648 + ((m_failedInvocationNumbers == null) ? 0 : m_failedInvocationNumbers649 .hashCode());650 result = prime * result651 + ((m_xmlGroups == null || m_xmlGroups.getRun() == null) ? 0 : m_xmlGroups.getRun().getIncludes().hashCode());652 result = prime * result + ((m_isJUnit == null) ? 0 : m_isJUnit.hashCode());653 result = prime * result654 + ((m_xmlGroups == null) ? 0 : m_xmlGroups.getDefines().hashCode());655 result = prime * result656 + ((m_methodSelectors == null) ? 0 : m_methodSelectors.hashCode());657 result = prime * result + ((m_name == null) ? 0 : m_name.hashCode());658 result = prime * result659 + ((m_parallel == null) ? 0 : m_parallel.hashCode());660 result = prime * result661 + ((m_parameters == null) ? 0 : m_parameters.hashCode());662 result = prime * result663 + ((m_preserveOrder == null) ? 0 : m_preserveOrder.hashCode());664 result = prime665 * result666 + ((m_skipFailedInvocationCounts == null) ? 0667 : m_skipFailedInvocationCounts.hashCode());668 result = prime * result + m_threadCount;669 result = prime * result + ((m_timeOut == null) ? 0 : m_timeOut.hashCode());670 result = prime * result + ((m_verbose == null) ? 0 : m_verbose.hashCode());671 result = prime * result672 + ((m_xmlClasses == null) ? 0 : m_xmlClasses.hashCode());673 result = prime * result674 + ((m_xmlPackages == null) ? 0 : m_xmlPackages.hashCode());675 return result;676 }677 @Override678 public boolean equals(Object obj) {679 if (this == obj) {680 return true;681 }682 if (obj == null)683 return XmlSuite.f();684 if (getClass() != obj.getClass())685 return XmlSuite.f();686 XmlTest other = (XmlTest) obj;687 if (m_xmlGroups == null) {688 if (other.m_xmlGroups != null)689 return XmlSuite.f();690 } else {691 if (other.m_xmlGroups == null) {692 return false;693 }694 if ((m_xmlGroups.getRun() == null && other.m_xmlGroups != null)695 || m_xmlGroups.getRun() != null && other.m_xmlGroups == null) {696 return false;697 }698 if (!m_xmlGroups.getRun().getExcludes().equals(other.m_xmlGroups.getRun().getExcludes())) {699 return XmlSuite.f();700 }701 if (!m_xmlGroups.getRun().getIncludes().equals(other.m_xmlGroups.getRun().getIncludes())) {702 return XmlSuite.f();703 }704 if (!m_xmlGroups.getDefines().equals(other.m_xmlGroups.getDefines())) {705 return false;706 }707 }708 if (m_failedInvocationNumbers == null) {709 if (other.m_failedInvocationNumbers != null)710 return XmlSuite.f();711 } else if (!m_failedInvocationNumbers712 .equals(other.m_failedInvocationNumbers))713 return XmlSuite.f();714 if (m_isJUnit == null) {715 if (other.m_isJUnit != null && ! other.m_isJUnit.equals(XmlSuite.DEFAULT_JUNIT))716 return XmlSuite.f();717 } else if (!m_isJUnit.equals(other.m_isJUnit))718 return XmlSuite.f();719 if (m_methodSelectors == null) {720 if (other.m_methodSelectors != null)721 return XmlSuite.f();722 } else if (!m_methodSelectors.equals(other.m_methodSelectors))723 return XmlSuite.f();724 if (m_name == null) {725 if (other.m_name != null)726 return XmlSuite.f();727 } else if (!m_name.equals(other.m_name))728 return XmlSuite.f();729 if (m_parallel == null) {730 if (other.m_parallel != null)731 return XmlSuite.f();...

Full Screen

Full Screen

Source:Yaml.java Github

copy

Full Screen

...82 */83 public static StringBuilder toYaml(XmlSuite suite) {84 StringBuilder result = new StringBuilder();85 maybeAdd(result, "name", suite.getName(), null);86 maybeAdd(result, "junit", suite.isJUnit(), XmlSuite.DEFAULT_JUNIT);87 maybeAdd(result, "verbose", suite.getVerbose(),88 XmlSuite.DEFAULT_VERBOSE);89 maybeAdd(result, "threadCount", suite.getThreadCount(),90 XmlSuite.DEFAULT_THREAD_COUNT);91 maybeAdd(result, "dataProviderThreadCount",92 suite.getDataProviderThreadCount(),93 XmlSuite.DEFAULT_DATA_PROVIDER_THREAD_COUNT);94 maybeAdd(result, "timeOut", suite.getTimeOut(), null);95 maybeAdd(result, "parallel", suite.getParallel(),96 XmlSuite.DEFAULT_PARALLEL);97 maybeAdd(result, "skipFailedInvocationCounts",98 suite.skipFailedInvocationCounts(),99 XmlSuite.DEFAULT_SKIP_FAILED_INVOCATION_COUNTS);100 toYaml(result, "parameters", "", suite.getParameters());101 toYaml(result, suite.getPackages());102 if (suite.getListeners().size() > 0) {103 result.append("listeners:\n");104 toYaml(result, " ", suite.getListeners());105 }106 if (suite.getPackages().size() > 0) {107 result.append("packages:\n");108 toYaml(result, suite.getPackages());109 }110 if (suite.getTests().size() > 0) {111 result.append("tests:\n");112 for (XmlTest t : suite.getTests()) {113 toYaml(result, " ", t);114 }115 }116 if (suite.getChildSuites().size() > 0) {117 result.append("suite-files:\n");118 toYaml(result, " ", suite.getSuiteFiles());119 }120 return result;121 }122 private static void toYaml(StringBuilder result, String sp, XmlTest t) {123 String sp2 = sp + " ";124 result.append(sp).append("- name: ").append(t.getName()).append("\n");125 maybeAdd(result, sp2, "junit", t.isJUnit(), XmlSuite.DEFAULT_JUNIT);126 maybeAdd(result, sp2, "verbose", t.getVerbose(),127 XmlSuite.DEFAULT_VERBOSE);128 maybeAdd(result, sp2, "timeOut", t.getTimeOut(), null);129 maybeAdd(result, sp2, "parallel", t.getParallel(),130 XmlSuite.DEFAULT_PARALLEL);131 maybeAdd(result, sp2, "skipFailedInvocationCounts",132 t.skipFailedInvocationCounts(),133 XmlSuite.DEFAULT_SKIP_FAILED_INVOCATION_COUNTS);134 maybeAdd(result, "preserveOrder", sp2, t.getPreserveOrder(),135 XmlSuite.DEFAULT_PRESERVE_ORDER);136 toYaml(result, "parameters", sp2, t.getTestParameters());137 if (t.getIncludedGroups().size() > 0) {138 result.append(sp2).append("includedGroups: [ ")139 .append(Utils.join(t.getIncludedGroups(), ","))...

Full Screen

Full Screen

Source:GenerateFailedReports.java Github

copy

Full Screen

...149 xmlTest.setIncludedGroups(srcXmlTest.getIncludedGroups());150 xmlTest.setExcludedGroups(srcXmlTest.getExcludedGroups());151 xmlTest.setParallel(srcXmlTest.getParallel());152 xmlTest.setParameters(srcXmlTest.getLocalParameters());153 xmlTest.setJUnit(srcXmlTest.isJUnit());154 List<XmlClass> xmlClasses = createXmlClasses(methods, srcXmlTest);155 xmlTest.setXmlClasses(xmlClasses);156 }157 /**158 * @param methods The methods we want to represent159 * @param srcXmlTest 160 * @return A list of XmlClass objects (each representing a <class> tag) based161 * on the parameter methods162 */163 @SuppressWarnings({ "rawtypes", "deprecation" })164private List<XmlClass> createXmlClasses(List<ITestNGMethod> methods, XmlTest srcXmlTest) {165 List<XmlClass> result = Lists.newArrayList();166 Map<Class, Set<ITestNGMethod>> methodsMap= Maps.newHashMap();167 for (ITestNGMethod m : methods) {...

Full Screen

Full Screen

Source:FailureReporter.java Github

copy

Full Screen

...116 xmlTest.setIncludedGroups(srcXmlTest.getIncludedGroups());117 xmlTest.setExcludedGroups(srcXmlTest.getExcludedGroups());118 xmlTest.setParallel(srcXmlTest.getParallel());119 xmlTest.setParameters(srcXmlTest.getLocalParameters());120 xmlTest.setJUnit(srcXmlTest.isJUnit());121 List<XmlClass> xmlClasses = createClassReport(methods, srcXmlTest);122 xmlTest.setXmlClasses(xmlClasses);123 }124125 126 private List<XmlClass> createClassReport(List<ITestNGMethod> methods, XmlTest srcXmlTest) {127 List<XmlClass> result = Lists.newArrayList();128 Map<Class<?>, Set<ITestNGMethod>> methodsMap= Maps.newHashMap();129130 for (ITestNGMethod m : methods) {131 Object instances= m.getInstance();132 Class<?> clazz= instances == null || instances == null133 ? m.getRealClass()134 : instances.getClass(); ...

Full Screen

Full Screen

Source:SuiteEntry.java Github

copy

Full Screen

...41 {42 return m_suite.getTest();43 }44 45 public boolean isJUnit()46 {47 return m_suite.isJUnit();48 }4950 public UUID getTestID()51 {52 return m_testID;53 }5455 public void setTestID(UUID testid)56 {57 m_testID = testid;58 }59} ...

Full Screen

Full Screen

Source:5fd0a.java Github

copy

Full Screen

...3--- a/src/main/java/org/testng/xml/XmlTest.java4+++ b/src/main/java/org/testng/xml/XmlTest.java5@@ -186,7 +186,7 @@6 */7 public boolean isJUnit() {8 Boolean result = m_isJUnit;9- if (null == result) {10+ if (null == result || XmlSuite.DEFAULT_JUNIT.equals(result)) {11 result = m_suite.isJUnit();12 }13 14@@ -271,7 +271,7 @@15 16 public String getParallel() {17 String result = null;18- if (null != m_parallel) {19+ if (null != m_parallel || XmlSuite.DEFAULT_PARALLEL.equals(m_parallel)) {20 result = m_parallel;21 }22 else {...

Full Screen

Full Screen

isJUnit

Using AI Code Generation

copy

Full Screen

1package com.guru99.test;2import java.io.File;3import java.io.IOException;4import java.util.ArrayList;5import java.util.List;6import org.testng.TestNG;7import org.testng.xml.Parser;8import org.testng.xml.XmlClass;9import org.testng.xml.XmlSuite;10import org.testng.xml.XmlTest;11public class TestNGRunner {12 public static void main(String[] args) throws IOException {13 TestNG testNG = new TestNG();14 XmlSuite suite = new XmlSuite();15 suite.setName("Guru99 Suite");16 XmlTest test = new XmlTest(suite);17 test.setName("Guru99 Test");18 List<XmlClass> classes = new ArrayList<XmlClass>();19 classes.add(new XmlClass("com.guru99.test.TestNG_Demo"));20 test.setXmlClasses(classes) ;21 List<XmlSuite> suites = new ArrayList<XmlSuite>();22 suites.add(suite);23 testNG.setXmlSuites(suites);24 testNG.run();25 }26}27package com.guru99.test;28import org.testng.Assert;29import org.testng.annotations.Test;30public class TestNG_Demo {31 public void testPrintMessage() {32 System.out.println("Inside testPrintMessage()");33 Assert.assertEquals("Guru99", "Guru99");34 }35}36package com.guru99.test;37import org.testng.Assert;38import org.testng.annotations.Test;39public class TestNG_Demo {40 public void testPrintMessage() {41 System.out.println("Inside testPrintMessage()");42 Assert.assertEquals("Guru99", "Guru99");43 }44}

Full Screen

Full Screen

isJUnit

Using AI Code Generation

copy

Full Screen

1import org.testng.annotations.Test;2import org.testng.xml.XmlSuite;3public class TestNGXmlSuiteJUnit {4 public void testXmlSuiteJUnit() {5 XmlSuite xmlSuite = new XmlSuite();6 xmlSuite.setJUnit(true);7 System.out.println("Is JUnit: " + xmlSuite.isJUnit());8 }9}

Full Screen

Full Screen

isJUnit

Using AI Code Generation

copy

Full Screen

1public class TestNGXmlSuite {2 public static void main(String[] args) {3 XmlSuite suite = new XmlSuite();4 suite.setJUnit(true);5 System.out.println(suite.isJUnit());6 }7}

Full Screen

Full Screen

TestNG tutorial

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.

Chapters

  1. JUnit 5 vs. TestNG: Compare and explore the core differences between JUnit 5 and TestNG from the Selenium WebDriver viewpoint.
  2. Installing TestNG in Eclipse: Start installing the TestNG Plugin and learn how to set up TestNG in Eclipse to begin constructing a framework for your test project.
  3. Create TestNG Project in Eclipse: Get started with creating a TestNG project and write your first TestNG test script.
  4. Automation using TestNG: Dive into how to install TestNG in this Selenium TestNG tutorial, the fundamentals of developing an automation script for Selenium automation testing.
  5. Parallel Test Execution in TestNG: Here are some essential elements of parallel testing with TestNG in this Selenium TestNG tutorial.
  6. Creating TestNG XML File: Here is a step-by-step tutorial on creating a TestNG XML file to learn why and how it is created and discover how to run the TestNG XML file being executed in parallel.
  7. Automation with Selenium, Cucumber & TestNG: Explore for an in-depth tutorial on automation using Selenium, Cucumber, and TestNG, as TestNG offers simpler settings and more features.
  8. JUnit Selenium Tests using TestNG: Start running your regular and parallel tests by looking at how to run test cases in Selenium using JUnit and TestNG without having to rewrite the tests.
  9. Group Test Cases in TestNG: Along with the explanation and demonstration using relevant TestNG group examples, learn how to group test cases in TestNG.
  10. Prioritizing Tests in TestNG: Get started with how to prioritize test cases in TestNG for Selenium automation testing.
  11. Assertions in TestNG: Examine what TestNG assertions are, the various types of TestNG assertions, and situations that relate to Selenium automated testing.
  12. DataProviders in TestNG: Deep dive into learning more about TestNG's DataProvider and how to effectively use it in our test scripts for Selenium test automation.
  13. Parameterization in TestNG: Here are the several parameterization strategies used in TestNG tests and how to apply them in Selenium automation scripts.
  14. TestNG Listeners in Selenium WebDriver: Understand the various TestNG listeners to utilize them effectively for your next plan when working with TestNG and Selenium automation.
  15. TestNG Annotations: Learn more about the execution order and annotation attributes, and refer to the prerequisites required to set up TestNG.
  16. TestNG Reporter Log in Selenium: Find out how to use the TestNG Reporter Log and learn how to eliminate the need for external software with TestNG Reporter Class to boost productivity.
  17. TestNG Reports in Jenkins: Discover how to generate TestNG reports in Jenkins if you want to know how to create, install, and share TestNG reports in Jenkins.

Certification

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.

YouTube

Watch this complete tutorial to learn how you can leverage the capabilities of the TestNG framework for Selenium automation testing.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful