1package test.alwaysrun;
2
3import org.testng.Assert;
4import org.testng.annotations.BeforeClass;
5import org.testng.annotations.BeforeMethod;
6import org.testng.annotations.BeforeSuite;
7import org.testng.annotations.BeforeTest;
8import org.testng.annotations.Test;
9
10/**
11 * Tests alwaysRun on a before Configuration method.  Invoke this test
12 * by running group "A"
13 *
14 * @author cbeust
15 * @date Mar 11, 2006
16 */
17public class AlwaysRunBefore1 {
18  private static boolean m_beforeSuiteSuccess = false;
19  private static boolean m_beforeTestSuccess = false;
20  private static boolean m_beforeTestClassSuccess = false;
21  private static boolean m_beforeTestMethodSuccess = false;
22
23  @BeforeSuite(alwaysRun = true)
24  public void initSuite() {
25    m_beforeSuiteSuccess = true;
26  }
27
28  @BeforeTest(alwaysRun = true)
29  public void initTest() {
30    m_beforeTestSuccess = true;
31  }
32
33  @BeforeClass(alwaysRun = true)
34  public void initTestClass() {
35    m_beforeTestClassSuccess = true;
36  }
37
38  @BeforeMethod(alwaysRun = true)
39  public void initTestMethod() {
40    m_beforeTestMethodSuccess = true;
41  }
42
43  @Test(groups = "A")
44  public void foo() {
45    Assert.assertTrue(m_beforeSuiteSuccess);
46    Assert.assertTrue(m_beforeTestSuccess);
47    Assert.assertTrue(m_beforeTestClassSuccess);
48    Assert.assertTrue(m_beforeTestMethodSuccess);
49  }
50
51  public static boolean success() {
52    return m_beforeSuiteSuccess && m_beforeTestSuccess &&
53      m_beforeTestClassSuccess && m_beforeTestMethodSuccess;
54  }
55
56}
57