获取testng中@BeforeMethod和@AfterMethod中当前执行的@Test方法名

2024-03-25

我想打印当前正在执行的测试方法的名称@BeforeMethod and @AfterMethod using testng. Like :

public class LoginTest {

@Test
public void Test01_LoginPage(){
    //Some Code here
}


@Test
public void Test02_LoginPage(){
    //Some Code Here
}

@BeforeMethod
public void beforeTestCase(){
    //Print Test method name which is going to execute.
}

@AfterMethod
public void AfterTestCase(){
    //Print Test method name which is executed.
}
}

From 文档 http://testng.org/doc/documentation-main.html#native-dependency-injection:

public class LoginTest {

  @Test
  public void Test01_LoginPage() {
    //Some Code here
  }


  @Test
  public void Test02_LoginPage() {
    //Some Code Here
  }

  @BeforeMethod
  public void beforeTestCase(Method m) {
    System.out.println(m.getName());
  }

  @AfterMethod
  public void AfterTestCase(Method m) {
    System.out.println(m.getName());
  }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

获取testng中@BeforeMethod和@AfterMethod中当前执行的@Test方法名 的相关文章

随机推荐