01: package test.dataprovider;
02:
03: import org.testng.Assert;
04: import org.testng.annotations.BeforeClass;
05: import org.testng.annotations.BeforeMethod;
06: import org.testng.annotations.BeforeSuite;
07: import org.testng.annotations.BeforeTest;
08: import org.testng.annotations.DataProvider;
09: 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")
25: public Object[][] createData() {
26: Assert.assertTrue(m_beforeSuite,
27: "beforeSuite should have been invoked");
28: Assert.assertTrue(m_beforeTest,
29: "beforeTest should have been invoked");
30: Assert.assertTrue(m_beforeClass,
31: "beforeClass should have been invoked");
32: Assert.assertFalse(m_beforeTestMethod,
33: "beforeMethod should not have been invoked");
34: return new Object[][] { new Object[] { "Test" } };
35: }
36:
37: @Test(dataProvider="test1")
38: public void verifyNames(Object p) {
39: // do nothing
40: }
41:
42: @BeforeSuite
43: public void setUpSuite() {
44: m_beforeSuite = true;
45: ppp("BEFORE SUITE");
46: }
47:
48: @BeforeTest
49: public void setUpTest() {
50: m_beforeTest = true;
51: ppp("BEFORE TEST");
52: }
53:
54: @BeforeClass
55: public void setUpClass() {
56: m_beforeClass = true;
57: ppp("BEFORE TEST CLASS");
58: }
59:
60: @BeforeMethod
61: public void setUp() {
62: m_beforeTestMethod = true;
63: ppp("BEFORE TEST METHOD");
64: }
65:
66: private static void ppp(String s) {
67: if (false) {
68: System.out.println("[ConfigurationAndDataProvidersTest] "
69: + s);
70: }
71: }
72:
73: }
|