单元测试Java类有注释,如何在没有注释的情况下测试这个类
EAX示例:
1 @Schema // you don't need to care what Schema annotation is
2 public class A {
3 public Schema getSchema() {
4 Schema schema = getClass().getAnnotation(Schema.class);
5 if (schema == null) {
6 throw new IllegalStateException("Schema annotation is missing for class " + getClass().getName());
7 }
8 return schema;
9 }
10 }
如何编写能够覆盖第6行的单元测试。 现在我只能讲第4、5、8行
# 1 楼答案
只有当存在扩展
class A
的子类时,您的场景才有意义。所以要测试它,您可以创建一个子类并测试它