1 package test.inject;
2 
3 import org.testng.Assert;
4 import org.testng.ITestContext;
5 import org.testng.TestListenerAdapter;
6 import org.testng.TestNG;
7 import org.testng.annotations.Parameters;
8 import org.testng.annotations.Test;
9 import org.testng.xml.XmlTest;
10 
11 import test.SimpleBaseTest;
12 
13 public class InjectTestContextTest extends SimpleBaseTest {
14 
15   @Test(enabled = false)
verifyTestContextInjection(ITestContext tc, XmlTest xmlTest)16   public void verifyTestContextInjection(ITestContext tc, XmlTest xmlTest) {
17     TestNG tng = create();
18     tng.setTestClasses(new Class[] { Sample.class });
19     TestListenerAdapter tla = new TestListenerAdapter();
20     tng.addListener(tla);
21     tng.run();
22 
23     Assert.assertEquals(xmlTest.getName(), "Injection");
24     Assert.assertEquals(tla.getPassedTests().size(), 1);
25     Assert.assertEquals(tla.getPassedTests().get(0).getMethod().getMethodName(), "f");
26   }
27 
28   @Parameters("string")
29   @Test(enabled = true)
injectionAndParameters(String s, ITestContext ctx)30   public void injectionAndParameters(String s, ITestContext ctx) {
31   }
32 }
33