【发布时间】:2016-05-03 00:06:39
【问题描述】:
我有一个用于注释 TestNG 测试的 TestInfo 接口,如下所示:
public @interface TestInfo {
/**
* Test case ID
*/
public String[] id();
boolean deploy() default true;
}
在上面的例子中,id() 是一个 String 类型的数组(String[ ])。现在我的 testng 测试看起来像这样:
@TestInfo(id={"C9114", "C9115"})
@Test
public class testTrial() {
...something
}
如何读取这个注释数组并在 for 循环中处理每个 ids。例如,我可以想到像get the test method 这样的方法,然后注释并检查每个 id,如下所示...
Map<Object, Object> map = new HashMap<Object, Object>();
Method method = result.getMethod().getConstructorOrMethod().getMethod();
TestInfo annotation = method.getAnnotation(TestInfo.class);
int status = 0;
try {
if (annotation!=null) {
for(;;/*each id*/){
map.put("id",annotation.id().substring(1));
switch (status) {
case ITestResult.SUCCESS:
map.put("result", STATUS.PASSED.getValue());
case ITestResult.FAILURE:
map.put("result", STATUS.AUTO_FAIL.getValue());
case ITestResult.SKIP:
map.put("result", STATUS.AUTO_SKIPPED.getValue());
default:
map.put("result", STATUS.UNTESTED.getValue());
}
ApiIntegration.addTestResult(map);
}
}
当我试图存储与测试相关联的 id 和结果时...我想知道正确的做法是什么?
【问题讨论】:
标签: java testing annotations automated-tests testng