1 package test.configuration; 2 3 import org.testng.Assert; 4 import org.testng.ITestContext; 5 import org.testng.ITestNGMethod; 6 import org.testng.annotations.BeforeMethod; 7 import org.testng.annotations.Test; 8 9 import java.lang.reflect.Method; 10 11 public class BeforeMethodTest { 12 private Method m_method; 13 private ITestContext m_context; 14 15 @BeforeMethod before(Method m, ITestContext ctx)16 public void before(Method m, ITestContext ctx) { 17 m_method = m; 18 m_context = ctx; 19 } 20 21 @Test mainTest()22 public void mainTest() { 23 Assert.assertEquals(m_method.getName(), "mainTest"); 24 ITestNGMethod[] methods = m_context.getAllTestMethods(); 25 Assert.assertEquals(1, methods.length); 26 Assert.assertEquals(methods[0].getMethod().getName(), "mainTest"); 27 28 } 29 } 30