• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package test;
2 
3 import org.testng.annotations.Test;
4 
5 /**
6  * This class tests invocationCount and successPercentage
7  *
8  * @author cbeust
9  */
10 public class InvocationAndSuccessPercentageTest extends BaseTest {
11 
12    @Test
invocationCount()13     public void invocationCount() {
14       addClass("test.sample.InvocationCountTest");
15       addIncludedGroup("invocationOnly");
16       run();
17       String[] passed = {
18           "tenTimesShouldSucceed",
19       };
20       String[] failed = {
21       };
22       verifyResults(getPassedTests(), 10, "passed tests");
23 //      Map passedTests = getPassedTests();
24 //      Set keys = passedTests.keySet();
25 //      Object firstKey = keys.iterator().next();
26 //      ITestResult passedResult = (ITestResult) passedTests.get(firstKey);
27 //      int n = passedResult.getPassedMethods().size();
28 //      assert n == 10 :
29 //        "Expected 10 tests to have passed, but only found " + n;
30       verifyTests("Passed", passed, getPassedTests());
31       verifyTests("Failed", failed, getFailedTests());
32     }
33 
34    /**
35     * Result expected:
36     * 8 passed
37     * 2 failed but within success percentage
38     */
39    @Test
successPercentageThatSucceeds()40    public void successPercentageThatSucceeds() {
41      addClass("test.sample.InvocationCountTest");
42      addIncludedGroup("successPercentageThatSucceedsOnly");
43      run();
44      String[] passed = {
45          "successPercentageShouldSucceed",
46      };
47      String[] failed = {
48      };
49      String[] failedButWithinSuccessPercentage = {
50          "successPercentageShouldSucceed",
51      };
52      verifyTests("FailedButWithinSuccessPercentage",
53          failedButWithinSuccessPercentage, getFailedButWithinSuccessPercentageTests());
54      verifyTests("Passed", passed, getPassedTests());
55      verifyTests("Failed", failed, getFailedTests());
56 
57      // Should have 8 passed, 2 failed but within success percentage
58      verifyResults(getPassedTests(), 8, "passed tests");
59      verifyResults(
60        getFailedButWithinSuccessPercentageTests(), 2,
61        "failed_but_within_success_percentage_tests");
62    }
63 
64    /**
65     * Result expected:
66     * 8 passed
67     * 1 failed but within success percentage
68     * 1 failed
69     */
70    @Test
successPercentageThatFails()71    public void successPercentageThatFails() {
72      addClass(test.sample.InvocationCountTest.class);
73      addIncludedGroup("successPercentageThatFailsOnly");
74      run();
75      String[] passed = {
76          "successPercentageShouldFail",
77      };
78      String[] failed = {
79          "successPercentageShouldFail",
80      };
81      String[] failedButWithinSuccessPercentage = {
82          "successPercentageShouldFail",
83      };
84      verifyTests("FailedButWithinSuccessPercentage",
85          failedButWithinSuccessPercentage, getFailedButWithinSuccessPercentageTests());
86      verifyTests("Passed", passed, getPassedTests());
87      verifyTests("Failed", failed, getFailedTests());
88 
89      // Should have 8 passed, 2 failed but within success percentage
90      verifyResults(getPassedTests(), 8, "passed tests");
91      verifyResults(getFailedTests(), 1, "failed tests");
92      verifyResults(
93        getFailedButWithinSuccessPercentageTests(), 1,
94        "failed_but_within_success_percentage_tests");
95    }
96 
ppp(String s)97    public static void ppp(String s) {
98     System.out.println("[Invocation] " + s);
99   }
100 
101 }
102