01: package test.sample;
02:
03: /**
04: * This class is used to test invocationCountTest
05: *
06: * @author cbeust
07: * @author <a href='mailto:the_mindstorm@evolva.ro'>Alexandru Popescu</a>
08: */
09: public class InvocationCountTest {
10: private static int m_count = 0;
11:
12: /**
13: * @testng.after-suite groups = "invocationOnly"
14: */
15: public void cleanUp() {
16: m_count = 0;
17: m_count2 = 0;
18: m_count3 = 0;
19: }
20:
21: /**
22: * @testng.test invocationCount = 10 groups="invocationOnly"
23: */
24: public void tenTimesShouldSucceed() {
25: m_count++;
26: }
27:
28: private static int m_count2 = 0;
29:
30: /**
31: * Invocation + Success percentage test.
32: * This method will work the first 8 times and fail after that, but overall
33: * the test should still pass because successPercentage = 80
34: *
35: * @testng.test groups="successPercentageThatSucceedsOnly" invocationCount=10 successPercentage = 80
36: */
37: public void successPercentageShouldSucceed() {
38: if (m_count2 >= 8) {
39: throw new RuntimeException(
40: "Called more than eight times : " + m_count2);
41: }
42: m_count2++;
43: }
44:
45: private static int m_count3 = 0;
46:
47: /**
48: * Invocation + Success percentage test
49: * This method will work the first 8 times and fail after that.
50: * One of the failures will fall under the percentage tolerance but the next one
51: * will not.
52: *
53: * @testng.test groups="successPercentageThatFailsOnly" invocationCount=10 successPercentage=90
54: */
55: public void successPercentageShouldFail() {
56: if (m_count3 >= 8) {
57: throw new RuntimeException(
58: "Called more than eight times : " + m_count3);
59: }
60: m_count3++;
61: }
62:
63: /**
64: * @testng.after-class groups="invocationOnly"
65: */
66: public void verify() {
67: assert 10 == m_count : "Method should have been invoked 10 times but was invoked "
68: + m_count + " times";
69: }
70:
71: public static void ppp(String s) {
72: System.out.println("[InvocationCount] " + s);
73: }
74:
75: }
|