01: package test.thread;
02:
03: import org.testng.Assert;
04: import org.testng.TestListenerAdapter;
05: import org.testng.TestNG;
06: import org.testng.annotations.Test;
07:
08: public class FactoryTest {
09:
10: @Test
11: /**
12: * In non-parallel mode, we should only have one thread id
13: * for the two methods invoked on B.
14: */
15: public void verifyFactoryNotParallel() {
16: runTest(null, 1);
17: }
18:
19: /**
20: * In parallel mode "methods", we should have as many thread id's
21: * as there are test methods on B (2).
22: */
23: @Test
24: public void verifyFactoryParallelMethods() {
25: runTest("methods", 2);
26: }
27:
28: @Test(groups="broken",description="Known bug: when parallel='tests', tests returned" + " by a @Factory are run in the same thread")
29: public void verifyFactoryParallelTests() {
30: runTest("tests", 2);
31: }
32:
33: private void runTest(String parallelMode, int expectedThreadIdCount) {
34: TestNG tng = new TestNG();
35: tng.setVerbose(0);
36: tng.setTestClasses(new Class[] { FactorySampleTest.class });
37: if (parallelMode != null) {
38: tng.setParallel(parallelMode);
39: }
40: TestListenerAdapter tla = new TestListenerAdapter();
41: tng.addListener(tla);
42:
43: B.setUp();
44: tng.run();
45:
46: Assert.assertEquals(tla.getPassedTests().size(), 2);
47: Assert
48: .assertEquals(B.m_threadIds.size(),
49: expectedThreadIdCount);
50:
51: // ppp("# TESTS RUN " + tla.getPassedTests().size()
52: // + " ID:" + B.m_threadIds.size());
53: }
54:
55: private void ppp(String string) {
56: System.out.println("[FactoryTest] " + string);
57: }
58:
59: }
|