1 package test.configuration; 2 3 import static org.testng.Assert.assertFalse; 4 import static org.testng.Assert.assertTrue; 5 6 import org.testng.annotations.AfterClass; 7 import org.testng.annotations.AfterMethod; 8 import org.testng.annotations.AfterSuite; 9 import org.testng.annotations.BeforeClass; 10 import org.testng.annotations.BeforeMethod; 11 import org.testng.annotations.Test; 12 13 public class MethodCallOrderTest { 14 public static boolean s_beforeSuite; 15 public static boolean s_beforeTest; 16 public static boolean s_beforeClass; 17 public static boolean s_beforeMethod; 18 19 @BeforeClass beforeClass()20 public void beforeClass() { 21 assertTrue(s_beforeSuite); 22 assertTrue(s_beforeTest); 23 assertFalse(s_beforeClass); 24 assertFalse(s_beforeMethod); 25 26 s_beforeClass = true; 27 } 28 29 @AfterSuite cleanUp()30 public void cleanUp() { 31 s_beforeSuite = false; 32 s_beforeTest = false; 33 s_beforeClass = false; 34 s_beforeMethod = false; 35 } 36 37 38 @BeforeMethod beforeMethod()39 public void beforeMethod() { 40 assertTrue(s_beforeSuite); 41 assertTrue(s_beforeTest); 42 assertTrue(s_beforeClass); 43 assertFalse(s_beforeMethod); 44 s_beforeMethod = true; 45 } 46 47 @Test realTest()48 public void realTest() { 49 assertTrue(s_beforeSuite); 50 assertTrue(s_beforeTest); 51 assertTrue(s_beforeClass); 52 assertTrue(s_beforeMethod); 53 } 54 55 @AfterMethod afterMethod()56 public void afterMethod() { 57 assertFalse(ExternalConfigurationClass.s_afterMethod, "afterTestMethod shouldn't have been run"); 58 assertFalse(ExternalConfigurationClass.s_afterClass, "afterTestClass shouldn't have been run"); 59 assertFalse(ExternalConfigurationClass.s_afterTest, "afterTest should haven't been run"); 60 61 ExternalConfigurationClass.s_afterMethod = true; 62 } 63 64 @AfterClass afterClass()65 public void afterClass() { 66 assertTrue(ExternalConfigurationClass.s_afterMethod, "afterTestMethod should have been run"); 67 assertFalse(ExternalConfigurationClass.s_afterClass, "afterTestClass shouldn't have been run"); 68 assertFalse(ExternalConfigurationClass.s_afterTest, "afterTest should haven't been run"); 69 ExternalConfigurationClass.s_afterClass = true; 70 } 71 } 72