1 package test.configuration;
2 
3 import org.testng.Assert;
4 import org.testng.annotations.AfterTest;
5 import org.testng.annotations.BeforeTest;
6 import org.testng.annotations.DataProvider;
7 import org.testng.annotations.Factory;
8 import org.testng.annotations.Test;
9 
10 /**
11  * Make sure that @BeforeTest is only called once if a factory is used
12  *
13  * @author Cedric Beust <cedric@beust.com>
14  */
15 public class SingleConfigurationTest {
16 
17   private static int m_before;
18 
19   @Factory(dataProvider = "dp")
SingleConfigurationTest(int n)20   public SingleConfigurationTest(int n) {
21   }
22 
23   @DataProvider
dp()24   public static Object[][] dp() {
25     return new Object[][] {
26         new Object[] { 42 },
27         new Object[] { 43 },
28     };
29   }
30 
31   @BeforeTest
bt()32   public void bt() {
33     m_before++;
34   }
35 
36   @Test
verify()37   public void verify() {
38     Assert.assertEquals(m_before, 1);
39   }
40 }
41