Search in sources :

Example 1 with ITestAnnotation

use of org.testng.annotations.ITestAnnotation 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());
}
Also used : XmlSuite(org.testng.xml.XmlSuite) ITestAnnotation(org.testng.annotations.ITestAnnotation) IAnnotationFinder(org.testng.internal.annotations.IAnnotationFinder) XmlTest(org.testng.xml.XmlTest) ArrayList(java.util.ArrayList) XmlClass(org.testng.xml.XmlClass) XmlClass(org.testng.xml.XmlClass)

Aggregations

ArrayList (java.util.ArrayList)1 ITestAnnotation (org.testng.annotations.ITestAnnotation)1 IAnnotationFinder (org.testng.internal.annotations.IAnnotationFinder)1 XmlClass (org.testng.xml.XmlClass)1 XmlSuite (org.testng.xml.XmlSuite)1 XmlTest (org.testng.xml.XmlTest)1