?Java 单元测试报错:Test class should have exactly one public zero-argument constructor?
public class Test{
private String a;
private int b;
}
public Test(String a, int b){
this.a = a;
this.b = b;
}
public boolean t1(String s){
if(s.length()){
return true;
}else{
return false;
}
}
@Test
public void test1(){
Test t = new Test("aaa", 5);
t.t1("123");
}
运行程序出现:
java.lang.Exception:
Test class should have exactly one public zero-argument constructor
原因:该类中包含了有参构造函数。解决办法:将有参构造函数的类独立出来即可。