@Test(dataProvider = "dp") public void testParse(String fileName, boolean shouldWork) { SuiteXmlParser parser = new SuiteXmlParser(); try (FileInputStream stream = new FileInputStream(new File(PARENT, fileName))) { XmlSuite suite = parser.parse(fileName, stream, false); if (!shouldWork) { Assert.fail("Parsing of " + fileName + " is supposed to fail"); } } catch (Exception e) { if (shouldWork) { Assert.fail("Parsing of " + fileName + " is supposed to work"); } } } }
@Test(description = "GITHUB-1787") public void testParameterInclusion() throws IOException { SuiteXmlParser parser = new SuiteXmlParser(); String file = "src/test/resources/yaml/1787.xml"; XmlSuite xmlSuite = parser.parse(file, new FileInputStream(file), false); StringBuilder yaml = org.testng.internal.Yaml.toYaml(xmlSuite); Matcher m = Pattern.compile("parameters:").matcher(yaml.toString()); int count = 0; while (m.find()) { count++; } assertThat(count).isEqualTo(5); File newSuite = File.createTempFile("suite", ".xml"); newSuite.deleteOnExit(); Files.writeFile(yaml.toString(), newSuite); assertThat(parser.parse(newSuite.getAbsolutePath(), new FileInputStream(file), false)) .isEqualTo(xmlSuite); }
@Test public void testParallelModeInheritanceInCommandlineMode() throws FileNotFoundException { SuiteXmlParser parser = new SuiteXmlParser(); String file = "src/test/resources/1636.xml"; XmlSuite xmlSuite = parser.parse(file, new FileInputStream(file), true); TestNG tng = new TestNG(); tng.setXmlSuites(Collections.singletonList(xmlSuite)); tng.run(); assertThat(Github1636Sample.threads).hasSize(3); }
@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 timeOutInParallelTestsFromXml() throws IOException { String file = "src/test/java/test/timeout/issue575.xml"; try (FileInputStream stream = new FileInputStream(file)) { SuiteXmlParser suiteParser = new SuiteXmlParser(); XmlSuite suite = suiteParser.parse(file, stream, true); setSuite(suite); run(); verifyPassedTests("timeoutShouldPass"); verifyFailedTests("timeoutShouldFailByException", "timeoutShouldFailByTimeOut"); } } }