use of org.testng.xml.XmlTest in project intellij-community by JetBrains.
the class TestNGXmlSuiteHelper method writeSuite.
public static File writeSuite(Map<String, Map<String, List<String>>> map, Map<String, String> testParams, String name, String rootPath, Logger logger) {
File xmlFile;
final XmlSuite xmlSuite = new XmlSuite();
xmlSuite.setParameters(testParams);
XmlTest xmlTest = new XmlTest(xmlSuite);
xmlTest.setName(name);
List<XmlClass> xmlClasses = new ArrayList<XmlClass>();
int idx = 0;
for (String className : map.keySet()) {
final XmlClass xmlClass = new XmlClass(className, idx++, false);
final Map<String, List<String>> collection = map.get(className);
if (collection != null) {
final ArrayList<XmlInclude> includedMethods = new ArrayList<XmlInclude>();
int mIdx = 0;
for (String methodName : collection.keySet()) {
final List<Integer> includes = new ArrayList<Integer>();
for (String include : collection.get(methodName)) {
try {
includes.add(Integer.parseInt(include));
} catch (NumberFormatException e) {
logger.log(e);
}
}
includedMethods.add(new XmlInclude(methodName, includes, mIdx++));
}
xmlClass.setIncludedMethods(includedMethods);
}
xmlClasses.add(xmlClass);
}
xmlTest.setXmlClasses(xmlClasses);
xmlFile = new File(rootPath, "temp-testng-customsuite.xml");
final String toXml = xmlSuite.toXml();
writeToFile(logger, xmlFile, toXml);
return xmlFile;
}
use of org.testng.xml.XmlTest in project intellij-community by JetBrains.
the class TestNGTreeHierarchyTest method testOneTestMethodWithMultipleInvocationCount.
@Test
public void testOneTestMethodWithMultipleInvocationCount() throws Exception {
final XmlSuite suite = new XmlSuite();
final XmlTest test = new XmlTest();
final XmlClass xmlClass = new XmlClass("a.ATest", false);
xmlClass.getIncludedMethods().add(new XmlInclude("test1", Arrays.asList(0, 1, 2), 0));
test.getClasses().add(xmlClass);
suite.getTests().add(test);
doTest(suite, "##teamcity[enteredTheMatrix]\n" + "\n" + "##teamcity[testSuiteStarted name ='ATest' locationHint = 'java:suite://a.ATest']\n" + "\n" + "##teamcity[testStarted name='ATest.test1|[0|]' locationHint='java:test://a.ATest.test1|[0|]']\n" + "\n" + "##teamcity[testFinished name='ATest.test1|[0|]']\n" + "\n" + "##teamcity[testStarted name='ATest.test1|[1|] (1)' locationHint='java:test://a.ATest.test1|[1|]']\n" + "\n" + "##teamcity[testFinished name='ATest.test1|[1|] (1)']\n" + "\n" + "##teamcity[testStarted name='ATest.test1|[2|] (2)' locationHint='java:test://a.ATest.test1|[2|]']\n" + "\n" + "##teamcity[testFinished name='ATest.test1|[2|] (2)']\n");
}
use of org.testng.xml.XmlTest in project intellij-community by JetBrains.
the class TestNGTreeHierarchyTest method testOneTestMethod.
@Test
public void testOneTestMethod() throws Exception {
final XmlSuite suite = new XmlSuite();
final XmlTest test = new XmlTest();
final XmlClass xmlClass = new XmlClass("a.ATest", false);
xmlClass.getIncludedMethods().add(new XmlInclude("test1"));
test.getClasses().add(xmlClass);
suite.getTests().add(test);
doTest(suite, "##teamcity[enteredTheMatrix]\n" + "\n" + "##teamcity[testSuiteStarted name ='ATest' locationHint = 'java:suite://a.ATest']\n" + "\n" + "##teamcity[testStarted name='ATest.test1|[0|]' locationHint='java:test://a.ATest.test1|[0|]']\n" + "\n" + "##teamcity[testFinished name='ATest.test1|[0|]']\n");
}
use of org.testng.xml.XmlTest in project druid by druid-io.
the class TestNG method initializeSuitesAndJarFile.
public void initializeSuitesAndJarFile() {
// so don't initialize suites twice.
if (m_isInitialized) {
return;
}
m_isInitialized = true;
if (m_suites.size() > 0) {
//to parse the suite files (<suite-file>), if any
for (XmlSuite s : m_suites) {
for (String suiteFile : s.getSuiteFiles()) {
try {
Collection<XmlSuite> childSuites = getParser(suiteFile).parse();
for (XmlSuite cSuite : childSuites) {
cSuite.setParentSuite(s);
s.getChildSuites().add(cSuite);
}
} catch (FileNotFoundException e) {
e.printStackTrace(System.out);
} catch (ParserConfigurationException e) {
e.printStackTrace(System.out);
} catch (SAXException e) {
e.printStackTrace(System.out);
} catch (IOException e) {
e.printStackTrace(System.out);
}
}
}
return;
}
//
for (String suitePath : m_stringSuites) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("suiteXmlPath: \"" + suitePath + "\"");
}
try {
Collection<XmlSuite> allSuites = getParser(suitePath).parse();
for (XmlSuite s : allSuites) {
// If test names were specified, only run these test names
if (m_testNames != null) {
m_suites.add(extractTestNames(s, m_testNames));
} else {
m_suites.add(s);
}
}
} catch (FileNotFoundException e) {
e.printStackTrace(System.out);
} catch (IOException e) {
e.printStackTrace(System.out);
} catch (ParserConfigurationException e) {
e.printStackTrace(System.out);
} catch (SAXException e) {
e.printStackTrace(System.out);
} catch (Exception ex) {
// Probably a Yaml exception, unnest it
Throwable t = ex;
while (t.getCause() != null) {
t = t.getCause();
}
// t.printStackTrace();
if (t instanceof TestNGException) {
throw (TestNGException) t;
} else {
throw new TestNGException(t);
}
}
}
// inside that jar path
if (m_jarPath != null && m_stringSuites.size() > 0) {
StringBuilder suites = new StringBuilder();
for (String s : m_stringSuites) {
suites.append(s);
}
Utils.log("TestNG", 2, "Ignoring the XML file inside " + m_jarPath + " and using " + suites + " instead");
return;
}
if (isStringEmpty(m_jarPath)) {
return;
}
// We have a jar file and no XML file was specified: try to find an XML file inside the jar
File jarFile = new File(m_jarPath);
try {
Utils.log("TestNG", 2, "Trying to open jar file:" + jarFile);
JarFile jf = new JarFile(jarFile);
// System.out.println(" result: " + jf);
Enumeration<JarEntry> entries = jf.entries();
List<String> classes = Lists.newArrayList();
boolean foundTestngXml = false;
while (entries.hasMoreElements()) {
JarEntry je = entries.nextElement();
if (je.getName().equals(m_xmlPathInJar)) {
Parser parser = getParser(jf.getInputStream(je));
m_suites.addAll(parser.parse());
foundTestngXml = true;
break;
} else if (je.getName().endsWith(".class")) {
int n = je.getName().length() - ".class".length();
classes.add(je.getName().replace("/", ".").substring(0, n));
}
}
if (!foundTestngXml) {
Utils.log("TestNG", 1, "Couldn't find the " + m_xmlPathInJar + " in the jar file, running all the classes");
XmlSuite xmlSuite = new XmlSuite();
xmlSuite.setVerbose(0);
xmlSuite.setName("Jar suite");
XmlTest xmlTest = new XmlTest(xmlSuite);
List<XmlClass> xmlClasses = Lists.newArrayList();
for (String cls : classes) {
XmlClass xmlClass = new XmlClass(cls);
xmlClasses.add(xmlClass);
}
xmlTest.setXmlClasses(xmlClasses);
m_suites.add(xmlSuite);
}
} catch (ParserConfigurationException ex) {
ex.printStackTrace();
} catch (SAXException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
use of org.testng.xml.XmlTest in project druid by druid-io.
the class TestNG method createCommandLineSuitesForClasses.
private List<XmlSuite> createCommandLineSuitesForClasses(Class[] classes) {
//
// See if any of the classes has an xmlSuite or xmlTest attribute.
// If it does, create the appropriate XmlSuite, otherwise, create
// the default one
//
XmlClass[] xmlClasses = Utils.classesToXmlClasses(classes);
Map<String, XmlSuite> suites = Maps.newHashMap();
IAnnotationFinder finder = m_configuration.getAnnotationFinder();
for (int i = 0; i < classes.length; i++) {
Class c = classes[i];
ITestAnnotation test = finder.findAnnotation(c, ITestAnnotation.class);
String suiteName = getDefaultSuiteName();
String testName = getDefaultTestName();
boolean isJUnit = false;
if (test != null) {
suiteName = defaultIfStringEmpty(test.getSuiteName(), suiteName);
testName = defaultIfStringEmpty(test.getTestName(), testName);
} else {
if (m_isMixed && JUnitTestFinder.isJUnitTest(c)) {
isJUnit = true;
testName = c.getName();
}
}
XmlSuite xmlSuite = suites.get(suiteName);
if (xmlSuite == null) {
xmlSuite = new XmlSuite();
xmlSuite.setName(suiteName);
suites.put(suiteName, xmlSuite);
}
if (m_dataProviderThreadCount != null) {
xmlSuite.setDataProviderThreadCount(m_dataProviderThreadCount);
}
XmlTest xmlTest = null;
for (XmlTest xt : xmlSuite.getTests()) {
if (xt.getName().equals(testName)) {
xmlTest = xt;
break;
}
}
if (xmlTest == null) {
xmlTest = new XmlTest(xmlSuite);
xmlTest.setName(testName);
xmlTest.setJUnit(isJUnit);
}
xmlTest.getXmlClasses().add(xmlClasses[i]);
}
return new ArrayList<XmlSuite>(suites.values());
}
Aggregations