01: package test.thread;
02:
03: import java.util.Arrays;
04: import java.util.HashMap;
05: import java.util.List;
06: import java.util.Map;
07:
08: import org.testng.Assert;
09: import org.testng.TestNG;
10: import org.testng.annotations.Test;
11: import org.testng.xml.XmlClass;
12: import org.testng.xml.XmlSuite;
13: import org.testng.xml.XmlTest;
14:
15: import test.BaseTest;
16:
17: public class ParallelTestTest extends BaseTest {
18:
19: @Test
20: public void verifyParallelNone() {
21: verifyExpected(XmlSuite.PARALLEL_NONE, 1);
22: }
23:
24: @Test(groups="broken")
25: public void verifyParallelTests() {
26: verifyExpected(XmlSuite.PARALLEL_TESTS, 2);
27: }
28:
29: @Test
30: public void verifyParallelMethods() {
31: verifyExpected(XmlSuite.PARALLEL_METHODS, 4);
32: }
33:
34: public static final String CLASS1 = "test.thread.Test1Test";
35: public static final String CLASS2 = "test.thread.Test2Test";
36:
37: private void createTest(XmlSuite xmlSuite, String className) {
38: XmlTest result = new XmlTest(xmlSuite);
39: List<XmlClass> classes = result.getXmlClasses();
40: XmlClass xmlClass = new XmlClass(className);
41: classes.add(xmlClass);
42: }
43:
44: private void verifyExpected(String parallelMode,
45: int expectedThreadCount) {
46: XmlSuite xmlSuite = new XmlSuite();
47: xmlSuite.setName("ParallelTestTest");
48: xmlSuite.setParallel(parallelMode);
49: createTest(xmlSuite, CLASS1);
50: createTest(xmlSuite, CLASS2);
51:
52: TestNG tng = new TestNG();
53: tng.setVerbose(0);
54: tng.setXmlSuites(Arrays.asList(new XmlSuite[] { xmlSuite }));
55:
56: Helper.reset();
57:
58: tng.run();
59:
60: Map<Long, Long>[] maps = new Map[] { Helper.getMap(CLASS1),
61: Helper.getMap(CLASS2), };
62:
63: Map<Long, Long> mergedMap = new HashMap<Long, Long>();
64: for (Map<Long, Long> m : maps) {
65: mergedMap.putAll(m);
66: }
67:
68: Assert.assertEquals(mergedMap.size(), expectedThreadCount);
69: }
70:
71: private static void ppp(String s) {
72: if (false) {
73: System.out.println("[SequentialTest] " + s);
74: }
75: }
76:
77: }
|