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 {
            Mapextends Annotation>, List> methodsForAnnotations = new LinkedHashMap();
            Mapextends Annotation>, List> fieldsForAnnotations = new LinkedHashMap();
            this.scanAnnotatedMembers(methodsForAnnotations, fieldsForAnnotations);
            this.methodsForAnnotations = makeDeeplyUnmodifiable(methodsForAnnotations);
            this.fieldsForAnnotations = makeDeeplyUnmodifiable(fieldsForAnnotations);
        }
    }

 

转载于:https://www.cnblogs.com/leafarmyarmy/p/11018127.html

你可能感兴趣的:(java.lang.IllegalArgumentException: Test class can only have one constructor)