Search in sources :

Example 11 with XmlSuite

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");
}
Also used : XmlInclude(org.testng.xml.XmlInclude) XmlSuite(org.testng.xml.XmlSuite) XmlTest(org.testng.xml.XmlTest) XmlClass(org.testng.xml.XmlClass) Test(org.junit.Test) XmlTest(org.testng.xml.XmlTest)

Example 12 with XmlSuite

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");
}
Also used : XmlInclude(org.testng.xml.XmlInclude) XmlSuite(org.testng.xml.XmlSuite) XmlTest(org.testng.xml.XmlTest) XmlClass(org.testng.xml.XmlClass) Test(org.junit.Test) XmlTest(org.testng.xml.XmlTest)

Example 13 with XmlSuite

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());
}
Also used : XmlSuite(org.testng.xml.XmlSuite) SuiteWorkerFactory(org.testng.internal.thread.graph.SuiteWorkerFactory) SuiteRunnerMap(org.testng.internal.SuiteRunnerMap) GraphThreadPoolExecutor(org.testng.internal.thread.graph.GraphThreadPoolExecutor) DynamicGraph(org.testng.internal.DynamicGraph)

Example 14 with XmlSuite

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();
    }
}
Also used : XmlSuite(org.testng.xml.XmlSuite) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) ParameterException(com.beust.jcommander.ParameterException) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) Parser(org.testng.xml.Parser) XmlTest(org.testng.xml.XmlTest) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) JarFile(java.util.jar.JarFile) File(java.io.File) XmlClass(org.testng.xml.XmlClass)

Example 15 with XmlSuite

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);
}
Also used : XmlSuite(org.testng.xml.XmlSuite) XmlMethodSelector(org.testng.xml.XmlMethodSelector) JDK15AnnotationFinder(org.testng.internal.annotations.JDK15AnnotationFinder)

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