我在getStatusAndAnnotation
课程中有Java方法TestListener
,如下所示:
public void getStatusAndAnnotation(ITestResult result) {
Map<Object, Object> map = new HashMap<Object, Object>();
Method method = result.getMethod().getConstructorOrMethod().getMethod();
Annotation annotation = TestListener.class.getAnnotation(TestInfo.class);
int status = 0;
try {
TestInfo testinfo = (TestInfo) annotation;
if (annotation!=null) {
for (String testId: testinfo.id()) {
map.put("id",testId.substring(1));
switch (status) {
case ITestResult.SUCCESS:
map.put("result", STATUS.PASSED.getValue());
case ITestResult.FAILURE:
map.put("result", STATUS.AUTO_FAIL.getValue());
default:
map.put("result", STATUS.UNTESTED.getValue());
}
ResultCollector.addTestResult(map);
}
} catch (SecurityException e) {
TestLogger.logInfo("Failed to find the annotation and the status of the test " + method);
e.printStackTrace();
}
}
我正在做的是获取Java TestNG方法,它的注释以及测试的状态,例如Pass,Fail等。将它们逐个放入地图中,如上面的代码所示 - 调用{{ 1}}和
map.put("id",testId.substring(1));
最后,我从ResultCollector类中调用方法map.put("result", STATUS.UNTESTED.getValue());
方法,该方法将保存所有这些映射。
但是,我看到人addTestResult()
如何使用object而不是map,以及在Java中实现此目的的更好方法是什么?