001: package test.configuration;
002:
003: import org.testng.Assert;
004:
005: public class MethodCallOrderTest {
006: public static boolean s_beforeSuite = false;
007: public static boolean s_beforeTest = false;
008: public static boolean s_beforeClass = false;
009: public static boolean s_beforeMethod = false;
010:
011: /**
012: * @testng.before-suite
013: */
014: public void init() {
015: ppp("@@@ INIT");
016: // Seems to vary depending where I run it
017: // assert ! s_beforeSuite : "BEFORESUITE SHOULD BE FALSE";
018: s_beforeSuite = true;
019: s_beforeTest = false;
020: s_beforeClass = false;
021: s_beforeMethod = false;
022: }
023:
024: private void ppp(String string) {
025: if (false) {
026: System.out.println("[MethodCallOrderTest] " + string);
027: }
028: }
029:
030: /**
031: * @testng.after-suite
032: */
033: public void cleanUp() {
034: ppp("@@@ CLEAN UP");
035: s_beforeSuite = false;
036: s_beforeTest = false;
037: s_beforeClass = false;
038: s_beforeMethod = false;
039: }
040:
041: /**
042: * @testng.before-test
043: */
044: public void beforeTest() {
045: Assert.assertTrue(s_beforeSuite);
046: Assert.assertFalse(s_beforeTest);
047: Assert.assertFalse(s_beforeClass);
048: Assert.assertFalse(s_beforeMethod);
049:
050: s_beforeTest = true;
051: }
052:
053: /**
054: * @testng.before-class
055: */
056: public void beforeClass() {
057: Assert.assertTrue(s_beforeSuite);
058: Assert.assertTrue(s_beforeTest);
059: Assert.assertTrue(!s_beforeClass);
060: Assert.assertTrue(!s_beforeMethod);
061:
062: s_beforeClass = true;
063: }
064:
065: /**
066: * @testng.before-method
067: */
068: public void beforeMethod() {
069: Assert.assertTrue(s_beforeSuite);
070: Assert.assertTrue(s_beforeTest);
071: Assert.assertTrue(s_beforeClass);
072: Assert.assertTrue(!s_beforeMethod);
073: s_beforeMethod = true;
074: }
075:
076: /**
077: * @testng.test
078: */
079: public void realTest() {
080: Assert.assertTrue(s_beforeSuite);
081: Assert.assertTrue(s_beforeTest);
082: Assert.assertTrue(s_beforeClass);
083: Assert.assertTrue(s_beforeMethod);
084: }
085:
086: /**
087: * @testng.after-method
088: */
089: public void afterMethod() {
090: Assert.assertTrue(!ExternalConfigurationClass.s_afterMethod,
091: "afterTestMethod shouldn't have been run");
092: Assert.assertTrue(!ExternalConfigurationClass.s_afterClass,
093: "afterTestClass shouldn't have been run");
094: Assert.assertTrue(!ExternalConfigurationClass.s_afterTest,
095: "afterTest should haven't been run");
096:
097: ExternalConfigurationClass.s_afterMethod = true;
098: }
099:
100: /**
101: * @testng.after-class
102: */
103: public void afterClass() {
104: Assert.assertTrue(ExternalConfigurationClass.s_afterMethod,
105: "afterTestMethod should have been run");
106: Assert.assertTrue(!ExternalConfigurationClass.s_afterClass,
107: "afterTestClass shouldn't have been run");
108: Assert.assertTrue(!ExternalConfigurationClass.s_afterTest,
109: "afterTest should haven't been run");
110: ExternalConfigurationClass.s_afterClass = true;
111: }
112: }
|