01: package test.dataprovider;
02:
03: import org.testng.Assert;
04: import org.testng.TestListenerAdapter;
05: import org.testng.TestNG;
06: import org.testng.annotations.Test;
07:
08: public class TestContextTest {
09:
10: @Test
11: public void verifyTen() {
12: verify("10", "verifyTen", 1, 0);
13: }
14:
15: @Test
16: public void verifyFive() {
17: verify("5", "verifyFive", 1, 0);
18: }
19:
20: @Test
21: public void verifySix() {
22: // Not including any group, so the two test methods should fail
23: verify(null, null, 0, 2);
24: }
25:
26: private void verify(String groupName, String passed,
27: int passedCount, int failedCount) {
28: TestNG tng = new TestNG();
29: tng.setVerbose(0);
30: tng.setTestClasses(new Class[] { TestContextSampleTest.class });
31: if (groupName != null) {
32: tng.setGroups(groupName);
33: }
34: TestListenerAdapter al = new TestListenerAdapter();
35: tng.addListener(al);
36: tng.run();
37:
38: if (passedCount > 0) {
39: Assert
40: .assertEquals(al.getPassedTests().size(),
41: passedCount);
42: Assert.assertEquals(al.getPassedTests().get(0).getMethod()
43: .getMethodName(), passed);
44: }
45:
46: if (failedCount > 0) {
47: Assert
48: .assertEquals(al.getFailedTests().size(),
49: failedCount);
50: }
51: }
52: }
|