1 package test.dataprovider;
2 
3 import org.testng.Assert;
4 import org.testng.annotations.BeforeClass;
5 import org.testng.annotations.BeforeMethod;
6 import org.testng.annotations.BeforeSuite;
7 import org.testng.annotations.BeforeTest;
8 import org.testng.annotations.DataProvider;
9 import org.testng.annotations.Test;
10 
11 /**
12  * Make sure that all before methods except beforeTestMethod are invoked
13  * before DataProvider.
14  *
15  * Created on Jan 19, 2006
16  * @author <a href="mailto:cedric@beust.com">Cedric Beust</a>
17  */
18 public class ConfigurationAndDataProvidersTest {
19   private boolean m_beforeSuite = false;
20   private boolean m_beforeTest = false;
21   private boolean m_beforeClass = false;
22   private boolean m_beforeTestMethod = false;
23 
24   @DataProvider(name = "test1")
createData()25   public Object[][] createData() {
26     Assert.assertTrue(m_beforeSuite, "beforeSuite should have been invoked");
27     Assert.assertTrue(m_beforeTest, "beforeTest should have been invoked");
28     Assert.assertTrue(m_beforeClass, "beforeClass should have been invoked");
29     Assert.assertFalse(m_beforeTestMethod, "beforeMethod should not have been invoked");
30     return new Object[][] { new Object[] { "Test" } };
31   }
32 
33   @Test(dataProvider = "test1")
verifyNames(Object p)34   public void verifyNames(Object p) {
35     // do nothing
36   }
37 
38 
39   @BeforeSuite
setUpSuite()40   public void setUpSuite () {
41     m_beforeSuite  = true;
42     ppp("BEFORE SUITE");
43   }
44 
45   @BeforeTest
setUpTest()46   public void setUpTest() {
47     m_beforeTest = true;
48     ppp("BEFORE TEST");
49   }
50 
51   @BeforeClass
setUpClass()52   public void setUpClass() {
53     m_beforeClass = true;
54     ppp("BEFORE TEST CLASS");
55   }
56 
57   @BeforeMethod
setUp()58   public void setUp() {
59     m_beforeTestMethod = true;
60     ppp("BEFORE TEST METHOD");
61   }
62 
ppp(String s)63   private static void ppp(String s) {
64     if (false) {
65       System.out.println("[ConfigurationAndDataProvidersTest] " + s);
66     }
67   }
68 
69 }
70