[英]How to test annotation in java using junit
班級有
@Info(name = "ABC", version = "1.1.1")
public class Test implements TestPlugin{
}
其中@Info是@interface注釋
我想編寫junit測試用例來驗證它的@info名稱和版本,我已經通過了。
您可以使用反射:
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");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.