01: package test;
02:
03: /**
04: * this test verifys that the test class is instantiated exactly once
05: * regardless of how many test methods we have, showing that TestNG
06: * semantics is quite different from JUnit
07: */
08: public class CtorCalledOnce {
09: public static int m_instantiated = 0;
10:
11: /**
12: * @testng.after-test
13: */
14: public void afterTest() {
15: m_instantiated = 0;
16: }
17:
18: public CtorCalledOnce() {
19: m_instantiated++;
20: }
21:
22: /**
23: * @testng.test
24: */
25: public void testMethod1() {
26: assert m_instantiated == 1 : "Expected 1, was invoked "
27: + m_instantiated + " times";
28: }
29:
30: /**
31: * @testng.test
32: */
33: public void testMethod2() {
34: assert m_instantiated == 1 : "Expected 1, was invoked "
35: + m_instantiated + " times";
36: }
37:
38: /**
39: * @testng.test
40: */
41: public void testMethod3() {
42: assert m_instantiated == 1 : "Expected 1, was invoked "
43: + m_instantiated + " times";
44: }
45:
46: }
|