1 package test.verify; 2 3 import org.testng.Assert; 4 import org.testng.TestListenerAdapter; 5 import org.testng.TestNG; 6 import org.testng.annotations.Test; 7 8 import test.SimpleBaseTest; 9 10 public class VerifyTest extends SimpleBaseTest { 11 12 private void runTest(Class<?> cls, int expected) { 13 TestNG tng = create(cls); 14 TestListenerAdapter tla = new TestListenerAdapter(); 15 tng.addListener(tla); 16 tng.run(); 17 18 Assert.assertEquals(tla.getPassedTests().size(), expected); 19 } 20 21 @Test 22 public void verifyWithAnnotation() { 23 runTest(VerifySampleTest.class, 4); 24 } 25 26 @Test 27 public void verifyWithoutAnnotation() { 28 runTest(VerifyNoListenersSampleTest.class, 3); 29 } 30 31 @Test 32 public void verifyTestListener() { 33 TestNG tng = create(Verify2SampleTest.class); 34 VerifyTestListener.m_count = 0; 35 tng.run(); 36 Assert.assertEquals(VerifyTestListener.m_count, 1); 37 } 38 39 @Test 40 public void verifyBaseClassTestListener() { 41 TestNG tng = create(Verify3SampleTest.class); 42 VerifyTestListener.m_count = 0; 43 tng.run(); 44 Assert.assertEquals(VerifyTestListener.m_count, 1); 45 } 46 47 } 48