班级
@Info(name = "ABC", version = "1.1.1")
public class Test implements TestPlugin{
}
@Info是@interface注释
我想编写junit测试用例来验证它的@info名称和版本,我已经通过了。
答案 0 :(得分:2)
您可以使用反射:
Annotation annotation = Test.class.getAnnotation(Info.class);
if(annotation instanceof Info){
Info info = (Info) annotation;
assertEquals("ABC", info.name());
assertEquals("1.1.1", info.version());
} else {
fail("Did not find annotation");
}