1package test.configuration;
2
3import org.testng.Assert;
4import org.testng.annotations.AfterTest;
5import org.testng.annotations.BeforeTest;
6import org.testng.annotations.DataProvider;
7import org.testng.annotations.Factory;
8import 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 */
15public class SingleConfigurationTest {
16
17  private static int m_before;
18
19  @Factory(dataProvider = "dp")
20  public SingleConfigurationTest(int n) {
21  }
22
23  @DataProvider
24  public static Object[][] dp() {
25    return new Object[][] {
26        new Object[] { 42 },
27        new Object[] { 43 },
28    };
29  }
30
31  @BeforeTest
32  public void bt() {
33    m_before++;
34  }
35
36  @Test
37  public void verify() {
38    Assert.assertEquals(m_before, 1);
39  }
40}
41