1 package test; 2 3 import org.testng.Assert; 4 import org.testng.annotations.Configuration; 5 import org.testng.annotations.Test; 6 7 8 /** 9 * 10 * @author Cedric Beust, May 5, 2004 11 * 12 */ 13 public class Test2 extends BaseTest { 14 private boolean m_initializedCorrectly = false; 15 16 @Configuration(beforeTestMethod = true) 17 // @BeforeMethod correctSetup()18 public void correctSetup() { 19 m_initializedCorrectly = true; 20 } 21 22 // Shouldn't be called 23 @Configuration(beforeTestMethod = true, groups = "excludeThisGroup") 24 // @BeforeMethod(groups = { "excludeThisGroup"} ) incorrectSetup()25 public void incorrectSetup() { 26 throw new RuntimeException("Should never be run"); 27 } 28 29 @Test noGroups()30 public void noGroups() { 31 addClass("test.sample.Sample1"); 32 run(); 33 String[] passed = { 34 "method1", 35 "method2", "method3", 36 "broken", "throwExpectedException1ShouldPass", 37 "throwExpectedException2ShouldPass" 38 }; 39 String[] failed = { 40 "throwExceptionShouldFail", "verifyLastNameShouldFail" 41 }; 42 verifyTests("Passed", passed, getPassedTests()); 43 verifyTests("Failed", failed, getFailedTests()); 44 } 45 46 @Test setUpWithGroups()47 public void setUpWithGroups() { 48 run(); 49 Assert.assertTrue(m_initializedCorrectly, "Should have run the correctSetup method"); 50 } 51 52 @Test partialGroupsClass()53 public void partialGroupsClass() { 54 addClass("test.sample.PartialGroupTest"); 55 addIncludedGroup("classGroup"); 56 run(); 57 String[] passed = { 58 "testMethodGroup", "testClassGroup" 59 }; 60 String[] failed = { 61 "testMethodGroupShouldFail", "testClassGroupShouldFail" 62 }; 63 verifyTests("Passed", passed, getPassedTests()); 64 verifyTests("Failed", failed, getFailedTests()); 65 66 // ppp("@@@@@@@@@@@@@@@@@@ PASSED TESTS"); 67 // for (Object o : getPassedTests().values()) { 68 // ppp("@@@@@@@@@@ PASSED:" + o); 69 // } 70 } 71 72 @Test partialGroupsMethod()73 public void partialGroupsMethod() { 74 addClass("test.sample.PartialGroupTest"); 75 addIncludedGroup("methodGroup"); 76 run(); 77 String[] passed = { 78 "testMethodGroup", 79 }; 80 String[] failed = { 81 "testMethodGroupShouldFail" 82 }; 83 verifyTests("Passed", passed, getPassedTests()); 84 verifyTests("Failed", failed, getFailedTests()); 85 } 86 87 } 88