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