繁体   English   中英

更改方法注释参数值

[英]Change method annotation parameter values

我正在尝试在运行时更改测试参数描述。 我看到的所有示例都涉及在类级别更改注释值。 但是,我想在方法级别上做到这一点。

我的示例代码如下:

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()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM