有没有一种方法可以在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");

最新更新