有没有办法在testNG中动态归因于描述注释?

Is there a way of dynamically attributing the description annotation in testNG?


    private String GIVEN = "";
    private String WHEN = "";
    private String THEN = "";


    @Test(description = GIVEN + WHEN + THEN)
    public void test() {

            GIVEN += "blah blah blah";
            WHEN += "blah blah blah";
            THEN += "blah blah blah";

    }

我想这样做 b/c我想在测试中使用的方法中添加描述。这样我就可以避免评论,并且可以在测试发生变化时使详细信息保持最新。

例如,我将在测试中调用此方法并同时更新给定的:

public void method(){
     code;
     GIVEN += "this code is doing this blah blah";
}

值只能是常量,所以我现在很困惑。

在TestNG.xml

上定义参数
<parameter name="blah blah blah" />
<parameter name="when" value="blah blah blah" />  
<parameter name="then" value="blah blah blah" /> 

然后可以像下面这样在你的测试用例中使用

  private String GIVEN = "";
   private String WHEN = "";
   private String THEN = "";
         
    @Test
         @Parameters({"given","when","then"})
            public void test() {
        
                    GIVEN += given;
                    WHEN += when;
                    THEN += then;
        
            }
ITestResult report = Reporter.getCurrentTestResult();
report.getMethod().setDescription("Whatever you would like to say");