use of org.testng.xml.XmlSuite 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.XmlSuite 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.XmlSuite in project druid by druid-io.
the class TestNG method runSuitesLocally.
/**
* This needs to be public for maven2, for now..At least
* until an alternative mechanism is found.
*/
public List<ISuite> runSuitesLocally() {
SuiteRunnerMap suiteRunnerMap = new SuiteRunnerMap();
if (m_suites.size() > 0) {
if (m_suites.get(0).getVerbose() >= 2) {
Version.displayBanner();
}
// Create a map with XmlSuite as key and corresponding SuiteRunner as value
for (XmlSuite xmlSuite : m_suites) {
createSuiteRunners(suiteRunnerMap, xmlSuite);
}
//
if (m_suiteThreadPoolSize == 1 && !m_randomizeSuites) {
// Single threaded and not randomized: run the suites in order
for (XmlSuite xmlSuite : m_suites) {
runSuitesSequentially(xmlSuite, suiteRunnerMap, getVerbose(xmlSuite), getDefaultSuiteName());
}
} else {
// Multithreaded: generate a dynamic graph that stores the suite hierarchy. This is then
// used to run related suites in specific order. Parent suites are run only
// once all the child suites have completed execution
DynamicGraph<ISuite> suiteGraph = new DynamicGraph<ISuite>();
for (XmlSuite xmlSuite : m_suites) {
populateSuiteGraph(suiteGraph, suiteRunnerMap, xmlSuite);
}
IThreadWorkerFactory<ISuite> factory = new SuiteWorkerFactory(suiteRunnerMap, 0, /* verbose hasn't been set yet */
getDefaultSuiteName());
GraphThreadPoolExecutor<ISuite> pooledExecutor = new GraphThreadPoolExecutor<ISuite>(suiteGraph, factory, m_suiteThreadPoolSize, m_suiteThreadPoolSize, Integer.MAX_VALUE, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
Utils.log("TestNG", 2, "Starting executor for all suites");
// Run all suites in parallel
pooledExecutor.run();
try {
pooledExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
pooledExecutor.shutdownNow();
} catch (InterruptedException handled) {
Thread.currentThread().interrupt();
error("Error waiting for concurrent executors to finish " + handled.getMessage());
}
}
} else {
setStatus(HAS_NO_TEST);
error("No test suite found. Nothing to run");
usage();
}
//
return Lists.newArrayList(suiteRunnerMap.values());
}
use of org.testng.xml.XmlSuite 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.XmlSuite in project druid by druid-io.
the class TestNG method initializeConfiguration.
private void initializeConfiguration() {
ITestObjectFactory factory = m_objectFactory;
//
// Install the listeners found in ServiceLoader (or use the class
// loader for tests, if specified).
//
addServiceLoaderListeners();
//
for (XmlSuite s : m_suites) {
for (String listenerName : s.getListeners()) {
Class<?> listenerClass = ClassHelper.forName(listenerName);
// If specified listener does not exist, a TestNGException will be thrown
if (listenerClass == null) {
throw new TestNGException("Listener " + listenerName + " was not found in project's classpath");
}
Object listener = ClassHelper.newInstance(listenerClass);
addListener(listener);
}
//
for (XmlMethodSelector methodSelector : s.getMethodSelectors()) {
addMethodSelector(methodSelector.getClassName(), methodSelector.getPriority());
}
//
if (s.getObjectFactory() != null) {
if (factory == null) {
factory = s.getObjectFactory();
} else {
throw new TestNGException("Found more than one object-factory tag in your suites");
}
}
}
m_configuration.setAnnotationFinder(new JDK15AnnotationFinder(getAnnotationTransformer()));
m_configuration.setHookable(m_hookable);
m_configuration.setConfigurable(m_configurable);
m_configuration.setObjectFactory(factory);
}
Aggregations