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";
}
值只能是一个常量,因此在这一点上我很困惑。
答案 0 :(得分:0)
在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;
}
答案 1 :(得分:0)
ITestResult report = Reporter.getCurrentTestResult();
report.getMethod().setDescription("Whatever you would like to say");