01: package test.factory;
02:
03: import test.triangle.CountCalls;
04:
05: /**
06: * this is like the FactoryTest, except it creates test instances in a separate
07: * class from the test class
08: */
09: public class FactoryInSeparateClass {
10: static private boolean m_wasRun = false;
11: static private int m_checkSum = 0;
12:
13: /**
14: * @testng.before-suite
15: */
16: public void init() {
17: m_wasRun = false;
18: m_checkSum = 0;
19: }
20:
21: public static void addToSum(int i) {
22: m_checkSum += i;
23: }
24:
25: /**
26: * @testng.factory
27: */
28: public Object[] createObjects() {
29: return new Object[] { new MyTest(1), new MyTest(2),
30: new MyTest(3), };
31: }
32:
33: /**
34: * @testng.test groups="testMethodOnFactoryClass" dependsOnGroups="MyTest"
35: */
36: public void checkSum() {
37: m_wasRun = true;
38: assert (m_checkSum == 6) : "Test instances made by factory did not invoke their test methods correctly. expected 6 but got "
39: + m_checkSum;
40: }
41:
42: public static boolean wasRun() {
43: return m_wasRun;
44: }
45: }
|