java.lang.IllegalArgumentException: Test class can only have one constructor

这个异常是在单元测试类的构造函数报的异常,单元测使用的是junit 4.12

出现原因分析:

查看源码:

TestClass类

 public TestClass(Class<?> clazz) {
        this.clazz = clazz;
        if (clazz != null && clazz.getConstructors().length > 1) {
            throw new IllegalArgumentException("Test class can only have one constructor");
        } else {
            Map<Class<? extends Annotation>, List<FrameworkMethod>> methodsForAnnotations = new LinkedHashMap();
            Map<Class<? extends Annotation>, List<FrameworkField>> fieldsForAnnotations = new LinkedHashMap();
            this.scanAnnotatedMembers(methodsForAnnotations, fieldsForAnnotations);
            this.methodsForAnnotations = makeDeeplyUnmodifiable(methodsForAnnotations);
            this.fieldsForAnnotations = makeDeeplyUnmodifiable(fieldsForAnnotations);
        }
    }

 

posted @ 2019-06-13 17:37  醉忆清吟  阅读(725)  评论(0编辑  收藏  举报