1 package test.name;
2 
3 import org.testng.Assert;
4 import org.testng.ITest;
5 import org.testng.annotations.AfterMethod;
6 import org.testng.annotations.BeforeMethod;
7 import org.testng.annotations.DataProvider;
8 import org.testng.annotations.Test;
9 
10 // From http://stackoverflow.com/q/33404335/4234729
11 public class ITestSample implements ITest {
12 
13   public ThreadLocal<String> testName = new ThreadLocal<>();
14 
15   @DataProvider(name = "dp", parallel = true)
getTests()16   public Object[][] getTests() {
17     return new Object[][]{new Object[]{"test1"},
18                           new Object[]{"test2"},
19                           new Object[]{"test3"},
20                           new Object[]{"test4"},
21                           new Object[]{"test5"}};
22   }
23 
24   @Test(dataProvider = "dp")
run(String testName)25   public void run(String testName) {
26     Assert.assertEquals(testName, this.testName.get());
27   }
28 
29   @BeforeMethod
init(Object[] testArgs)30   public void init(Object[] testArgs) {
31     testName.set((String) testArgs[0]);
32   }
33 
34   @AfterMethod
tearDown(Object[] testArgs)35   public void tearDown(Object[] testArgs) {
36     Assert.assertEquals((String) testArgs[0], this.testName.get());
37   }
38 
39   @Override
getTestName()40   public String getTestName() {
41     return testName.get();
42   }
43 }
44