我是 testNG 的新手,我有以下代码:
@BeforeMethod
public void getGroup(ITestAnnotation annotation){
System.out.println("Group Name is --" + annotation.getGroups()) ;
}
@Test(groups = { "MobilSite" })
public void test1(){
System.out.println("I am Running Mobile Site Test");
}
我想在之前的方法中使用组名,我尝试使用 ITestAnnotation
但是当我运行测试时出现以下错误
Method getGroup requires 1 parameters but 0 were supplied in the @Configuration annotation.
你能帮我从 XML 传递的参数吗?
最佳答案
使用reflected方法获取测试组如下:
@BeforeMethod
public void befMet(Method m){
Test t = m.getAnnotation(Test.class);
System.out.println(t.groups()[0]);//or however you want to use it.
}
关于java - 如何在 TestNG 中获取测试组名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31555992/