1 package test.xml; 2 3 import org.testng.Assert; 4 import org.testng.TestListenerAdapter; 5 import org.testng.TestNG; 6 import org.testng.TestNGException; 7 import org.testng.annotations.Test; 8 import org.testng.xml.XmlClass; 9 import org.testng.xml.XmlSuite; 10 import org.testng.xml.XmlTest; 11 12 import test.SimpleBaseTest; 13 14 import java.io.ByteArrayOutputStream; 15 import java.io.IOException; 16 import java.io.OutputStream; 17 import java.io.PrintStream; 18 import java.util.Arrays; 19 20 public class XmlVerifyTest extends SimpleBaseTest { 21 22 // private String getFinalPath(String file) { 23 // File currentDir = new File("."); 24 // String path = currentDir.getAbsolutePath(); 25 // char s = File.separatorChar; 26 // String testDir = System.getProperty("test.dir"); 27 // System.out.println("[XmlVerifyTest] test.dir:" + testDir); 28 // Assert.assertNotNull(testDir); 29 // path = path + s + testDir + s; 30 // return path + file; 31 // } 32 33 @Test simple()34 public void simple() { 35 XmlSuite suite = new XmlSuite(); 36 XmlTest test = new XmlTest(suite); 37 XmlClass xClass = new XmlClass(XmlVerifyTest.class); 38 test.getXmlClasses().add(xClass); 39 test.getExcludedGroups().add("fast"); 40 test.setVerbose(5); 41 42 suite.toXml(); 43 } 44 45 @Test(description="Ensure that TestNG stops without running any tests if some class" + 46 " included in suite is missing") handleInvalidSuites()47 public void handleInvalidSuites() { 48 TestListenerAdapter tla = new TestListenerAdapter(); 49 try { 50 TestNG tng = create(); 51 String testngXmlPath = getPathToResource("suite1.xml"); 52 tng.setTestSuites(Arrays.asList(testngXmlPath)); 53 tng.addListener(tla); 54 tng.run(); 55 } catch (TestNGException ex) { 56 Assert.assertEquals(tla.getPassedTests().size(), 0); 57 } 58 } 59 } 60