Search in sources :

Example 11 with XmlTest

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

the class RemoteTestNG method buildTestRunnerFactory.

/**
   * Override by the plugin if you need to configure differently the <code>TestRunner</code>
   * (usually this is needed if different listeners/reporters are needed).
   * <b>Note</b>: you don't need to worry about the wiring listener, because it is added
   * automatically.
   */
protected ITestRunnerFactory buildTestRunnerFactory() {
    //################### PATCH STARTS
    if (System.getProperty("testrunfactory") != null) {
        m_customTestRunnerFactory = (ITestRunnerFactory) ClassHelper.newInstance(ClassHelper.fileToClass(System.getProperty("testrunfactory")));
    //################## PATCH ENDS
    } else if (null == m_customTestRunnerFactory) {
        m_customTestRunnerFactory = new ITestRunnerFactory() {

            @Override
            public TestRunner newTestRunner(ISuite suite, XmlTest xmlTest, List<IInvokedMethodListener> listeners) {
                TestRunner runner = new TestRunner(getConfiguration(), suite, xmlTest, false, /*skipFailedInvocationCounts */
                listeners);
                if (m_useDefaultListeners) {
                    runner.addListener(new TestHTMLReporter());
                    runner.addListener(new JUnitXMLReporter());
                }
                return runner;
            }
        };
    }
    return m_customTestRunnerFactory;
}
Also used : TestHTMLReporter(org.testng.reporters.TestHTMLReporter) JUnitXMLReporter(org.testng.reporters.JUnitXMLReporter) ISuite(org.testng.ISuite) TestRunner(org.testng.TestRunner) ITestRunnerFactory(org.testng.ITestRunnerFactory) XmlTest(org.testng.xml.XmlTest) List(java.util.List)

Example 12 with XmlTest

use of org.testng.xml.XmlTest 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 13 with XmlTest

use of org.testng.xml.XmlTest 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 14 with XmlTest

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

Example 15 with XmlTest

use of org.testng.xml.XmlTest in project buck by facebook.

the class TestNGRunner method createXmlSuite.

private XmlSuite createXmlSuite(Class<?> c) {
    XmlSuite xmlSuite = new XmlSuite();
    xmlSuite.setName("TmpSuite");
    xmlSuite.setTimeOut(String.valueOf(defaultTestTimeoutMillis));
    XmlTest xmlTest = new XmlTest(xmlSuite);
    xmlTest.setName("TmpTest");
    xmlTest.setXmlClasses(Collections.singletonList(new XmlClass(c)));
    return xmlSuite;
}
Also used : XmlSuite(org.testng.xml.XmlSuite) XmlTest(org.testng.xml.XmlTest) XmlClass(org.testng.xml.XmlClass)

Aggregations

XmlTest (org.testng.xml.XmlTest)16 XmlSuite (org.testng.xml.XmlSuite)12 XmlClass (org.testng.xml.XmlClass)11 XmlInclude (org.testng.xml.XmlInclude)6 ArrayList (java.util.ArrayList)3 File (java.io.File)2 List (java.util.List)2 Test (org.junit.Test)2 ParameterException (com.beust.jcommander.ParameterException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Map (java.util.Map)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 IDEATestNGRemoteListener (org.testng.IDEATestNGRemoteListener)1 ISuite (org.testng.ISuite)1 ITestRunnerFactory (org.testng.ITestRunnerFactory)1 TestRunner (org.testng.TestRunner)1