我正在尝试在运行时更改测试参数说明。我看到的所有示例都涉及在类级别更改注释值。但是,我想在方法级别执行此操作。
我的示例代码如下:
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.lang.reflect.Method;
public class TestClass {
@BeforeMethod
public void beforeMethod(Method method){
Test annotation = method.getAnnotation(Test.class);
// I want to change description to "some modified description"
}
@Test(description = "some description")
public void test(){
System.out.println("in test");
}
}
注释参数不能更改,因为必须在编译时知道它们。
如果需要更改它,可以使用带有getter和setter的接口,而不是使用注释。
使用TestNG,您可以实现ITest
并像getTestName()
所描述的那样覆盖方法this answer。