Home | History | Annotate | Download | only in name
      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)
     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")
     25   public void run(String testName) {
     26     Assert.assertEquals(testName, this.testName.get());
     27   }
     28 
     29   @BeforeMethod
     30   public void init(Object[] testArgs) {
     31     testName.set((String) testArgs[0]);
     32   }
     33 
     34   @AfterMethod
     35   public void tearDown(Object[] testArgs) {
     36     Assert.assertEquals((String) testArgs[0], this.testName.get());
     37   }
     38 
     39   @Override
     40   public String getTestName() {
     41     return testName.get();
     42   }
     43 }
     44