Search in sources :

Example 1 with XmlClass

use of org.testng.xml.XmlClass in project powermock by powermock.

the class SimpleBaseTest method createXmlTest.

protected XmlTest createXmlTest(XmlSuite suite, String name, String... classes) {
    XmlTest result = new XmlTest(suite);
    int index = 0;
    result.setName(name);
    for (String c : classes) {
        XmlClass xc = new XmlClass(c, index++, true);
        result.getXmlClasses().add(xc);
    }
    return result;
}
Also used : XmlTest(org.testng.xml.XmlTest) XmlClass(org.testng.xml.XmlClass)

Example 2 with XmlClass

use of org.testng.xml.XmlClass in project powermock by powermock.

the class SimpleBaseTest method createXmlTest.

protected XmlTest createXmlTest(XmlSuite suite, String name, Class clazz, Class... classes) {
    XmlTest result = new XmlTest(suite);
    int index = 0;
    result.setName(name);
    XmlClass xc = new XmlClass(clazz.getName(), index++, true);
    result.getXmlClasses().add(xc);
    for (Class c : classes) {
        xc = new XmlClass(c.getName(), index++, true);
        result.getXmlClasses().add(xc);
    }
    return result;
}
Also used : XmlTest(org.testng.xml.XmlTest) XmlClass(org.testng.xml.XmlClass) XmlClass(org.testng.xml.XmlClass)

Example 3 with XmlClass

use of org.testng.xml.XmlClass in project intellij-community by JetBrains.

the class IDEARemoteTestNG method run.

public void run() {
    try {
        initializeSuitesAndJarFile();
        List<XmlSuite> suites = Lists.newArrayList();
        calculateAllSuites(m_suites, suites);
        if (suites.size() > 0) {
            for (XmlSuite suite : suites) {
                final List<XmlTest> tests = suite.getTests();
                for (XmlTest test : tests) {
                    try {
                        if (myParam != null) {
                            for (XmlClass aClass : test.getXmlClasses()) {
                                List<XmlInclude> includes = new ArrayList<XmlInclude>();
                                for (XmlInclude include : aClass.getIncludedMethods()) {
                                    includes.add(new XmlInclude(include.getName(), Collections.singletonList(Integer.parseInt(myParam)), 0));
                                }
                                aClass.setIncludedMethods(includes);
                            }
                        }
                    } catch (NumberFormatException e) {
                        System.err.println("Invocation number: expected integer but found: " + myParam);
                    }
                }
            }
            attachListeners(new IDEATestNGRemoteListener());
            super.run();
            System.exit(0);
        } else {
            System.out.println("##teamcity[enteredTheMatrix]");
            System.err.println("Nothing found to run");
        }
    } catch (Throwable cause) {
        cause.printStackTrace(System.err);
    }
}
Also used : XmlInclude(org.testng.xml.XmlInclude) XmlSuite(org.testng.xml.XmlSuite) XmlTest(org.testng.xml.XmlTest) ArrayList(java.util.ArrayList) XmlClass(org.testng.xml.XmlClass)

Example 4 with XmlClass

use of org.testng.xml.XmlClass in project intellij-community by JetBrains.

the class TestNGXmlSuiteHelper method writeSuite.

public static File writeSuite(Map<String, Map<String, List<String>>> map, Map<String, String> testParams, String name, String rootPath, Logger logger) {
    File xmlFile;
    final XmlSuite xmlSuite = new XmlSuite();
    xmlSuite.setParameters(testParams);
    XmlTest xmlTest = new XmlTest(xmlSuite);
    xmlTest.setName(name);
    List<XmlClass> xmlClasses = new ArrayList<XmlClass>();
    int idx = 0;
    for (String className : map.keySet()) {
        final XmlClass xmlClass = new XmlClass(className, idx++, false);
        final Map<String, List<String>> collection = map.get(className);
        if (collection != null) {
            final ArrayList<XmlInclude> includedMethods = new ArrayList<XmlInclude>();
            int mIdx = 0;
            for (String methodName : collection.keySet()) {
                final List<Integer> includes = new ArrayList<Integer>();
                for (String include : collection.get(methodName)) {
                    try {
                        includes.add(Integer.parseInt(include));
                    } catch (NumberFormatException e) {
                        logger.log(e);
                    }
                }
                includedMethods.add(new XmlInclude(methodName, includes, mIdx++));
            }
            xmlClass.setIncludedMethods(includedMethods);
        }
        xmlClasses.add(xmlClass);
    }
    xmlTest.setXmlClasses(xmlClasses);
    xmlFile = new File(rootPath, "temp-testng-customsuite.xml");
    final String toXml = xmlSuite.toXml();
    writeToFile(logger, xmlFile, toXml);
    return xmlFile;
}
Also used : XmlSuite(org.testng.xml.XmlSuite) ArrayList(java.util.ArrayList) XmlInclude(org.testng.xml.XmlInclude) XmlTest(org.testng.xml.XmlTest) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File) XmlClass(org.testng.xml.XmlClass)

Example 5 with XmlClass

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

Aggregations

XmlClass (org.testng.xml.XmlClass)11 XmlTest (org.testng.xml.XmlTest)11 XmlSuite (org.testng.xml.XmlSuite)8 XmlInclude (org.testng.xml.XmlInclude)6 ArrayList (java.util.ArrayList)3 File (java.io.File)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 List (java.util.List)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 IDEATestNGRemoteListener (org.testng.IDEATestNGRemoteListener)1 ITestAnnotation (org.testng.annotations.ITestAnnotation)1 IAnnotationFinder (org.testng.internal.annotations.IAnnotationFinder)1 Parser (org.testng.xml.Parser)1 SAXException (org.xml.sax.SAXException)1