Search in sources :

Example 16 with XmlSuite

use of org.testng.xml.XmlSuite 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)

Example 17 with XmlSuite

use of org.testng.xml.XmlSuite in project druid by druid-io.

the class RemoteTestNG method run.

@Override
public void run() {
    IMessageSender sender = m_serPort != null ? new SerializedMessageSender(m_host, m_serPort, m_ack) : new StringMessageSender(m_host, m_port);
    final MessageHub msh = new MessageHub(sender);
    msh.setDebug(isDebug());
    try {
        msh.connect();
        // We couldn't do this until now in debug mode since the .xml file didn't exist yet.
        // Now that we have connected with the Eclipse client, we know that it created the .xml
        // file so we can proceed with the initialization
        initializeSuitesAndJarFile();
        List<XmlSuite> suites = Lists.newArrayList();
        calculateAllSuites(m_suites, suites);
        //          + " and:" + suites.get(0).getChildSuites().size());
        if (suites.size() > 0) {
            int testCount = 0;
            for (int i = 0; i < suites.size(); i++) {
                testCount += (suites.get(i)).getTests().size();
            }
            GenericMessage gm = new GenericMessage(MessageHelper.GENERIC_SUITE_COUNT);
            gm.setSuiteCount(suites.size());
            gm.setTestCount(testCount);
            msh.sendMessage(gm);
            addListener(new RemoteSuiteListener(msh));
            setTestRunnerFactory(new DelegatingTestRunnerFactory(buildTestRunnerFactory(), msh));
            //        System.out.println("RemoteTestNG starting");
            super.run();
        } else {
            System.err.println("No test suite found. Nothing to run");
        }
    } catch (Throwable cause) {
        cause.printStackTrace(System.err);
    } finally {
        //      System.out.println("RemoteTestNG finishing: " + (getEnd() - getStart()) + " ms");
        msh.shutDown();
        if (!m_debug && !m_dontExit) {
            System.exit(0);
        }
    }
}
Also used : GenericMessage(org.testng.remote.strprotocol.GenericMessage) XmlSuite(org.testng.xml.XmlSuite) StringMessageSender(org.testng.remote.strprotocol.StringMessageSender) MessageHub(org.testng.remote.strprotocol.MessageHub) SerializedMessageSender(org.testng.remote.strprotocol.SerializedMessageSender) IMessageSender(org.testng.remote.strprotocol.IMessageSender)

Example 18 with XmlSuite

use of org.testng.xml.XmlSuite in project druid by druid-io.

the class TestNG method createCommandLineSuitesForMethods.

/**
   * @param commandLineMethods a string with the form "com.example.Foo.f1,com.example.Bar.f2"
   *
   * @return a list of XmlSuite objects that represent the list of classes and methods passed
   * in parameter.
   */
private List<XmlSuite> createCommandLineSuitesForMethods(List<String> commandLineMethods) {
    //
    // Create the <classes> tag
    //
    Set<Class> classes = Sets.newHashSet();
    for (String m : commandLineMethods) {
        Class c = ClassHelper.forName(splitMethod(m)[0]);
        if (c != null) {
            classes.add(c);
        }
    }
    List<XmlSuite> result = createCommandLineSuitesForClasses(classes.toArray(new Class[0]));
    //
    // Add the method tags
    //
    List<XmlClass> xmlClasses = Lists.newArrayList();
    for (XmlSuite s : result) {
        for (XmlTest t : s.getTests()) {
            xmlClasses.addAll(t.getClasses());
        }
    }
    for (XmlClass xc : xmlClasses) {
        for (String m : commandLineMethods) {
            String[] split = splitMethod(m);
            String className = split[0];
            if (xc.getName().equals(className)) {
                XmlInclude includedMethod = new XmlInclude(split[1]);
                xc.getIncludedMethods().add(includedMethod);
            }
        }
    }
    return result;
}
Also used : XmlInclude(org.testng.xml.XmlInclude) XmlSuite(org.testng.xml.XmlSuite) XmlTest(org.testng.xml.XmlTest) XmlClass(org.testng.xml.XmlClass) XmlClass(org.testng.xml.XmlClass)

Example 19 with XmlSuite

use of org.testng.xml.XmlSuite in project druid by druid-io.

the class TestNG method extractTestNames.

/**
   * If the XmlSuite contains at least one test named as testNames, return
   * an XmlSuite that's made only of these tests, otherwise, return the
   * original suite.
   */
private static XmlSuite extractTestNames(XmlSuite s, List<String> testNames) {
    List<XmlTest> tests = Lists.newArrayList();
    for (XmlTest xt : s.getTests()) {
        for (String tn : testNames) {
            if (xt.getName().equals(tn)) {
                tests.add(xt);
            }
        }
    }
    if (tests.size() == 0) {
        return s;
    } else {
        XmlSuite result = (XmlSuite) s.clone();
        result.getTests().clear();
        result.getTests().addAll(tests);
        return result;
    }
}
Also used : XmlSuite(org.testng.xml.XmlSuite) XmlTest(org.testng.xml.XmlTest)

Example 20 with XmlSuite

use of org.testng.xml.XmlSuite in project druid by druid-io.

the class TestNG method initializeCommandLineSuitesGroups.

private void initializeCommandLineSuitesGroups() {
    // If groups were specified on the command line, they should override groups
    // specified in the XML file
    boolean hasIncludedGroups = null != m_includedGroups && m_includedGroups.length > 0;
    boolean hasExcludedGroups = null != m_excludedGroups && m_excludedGroups.length > 0;
    List<XmlSuite> suites = m_cmdlineSuites != null ? m_cmdlineSuites : m_suites;
    if (hasIncludedGroups || hasExcludedGroups) {
        for (XmlSuite s : suites) {
            //set on each test, instead of just the first one of the suite
            for (XmlTest t : s.getTests()) {
                if (hasIncludedGroups) {
                    t.setIncludedGroups(Arrays.asList(m_includedGroups));
                }
                if (hasExcludedGroups) {
                    t.setExcludedGroups(Arrays.asList(m_excludedGroups));
                }
            }
        }
    }
}
Also used : XmlSuite(org.testng.xml.XmlSuite) XmlTest(org.testng.xml.XmlTest)

Aggregations

XmlSuite (org.testng.xml.XmlSuite)22 XmlTest (org.testng.xml.XmlTest)12 XmlClass (org.testng.xml.XmlClass)8 XmlInclude (org.testng.xml.XmlInclude)5 ArrayList (java.util.ArrayList)3 File (java.io.File)2 Test (org.junit.Test)2 SuiteRunnerMap (org.testng.internal.SuiteRunnerMap)2 Parser (org.testng.xml.Parser)2 XmlMethodSelector (org.testng.xml.XmlMethodSelector)2 ParameterException (com.beust.jcommander.ParameterException)1 CantRunException (com.intellij.execution.CantRunException)1 ExecutionException (com.intellij.execution.ExecutionException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1 Map (java.util.Map)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1