错误背景: 做测试的时候,为了偷懒,使用@Test注解代替main方法来执行代码,
public class Demo {
private int i;
public Demo(int i) {
this.i= i;
}
private void f(){
System.out.println("普通方法"+i);
}
@Test
public void method(){
Demo demo = new Demo(25);
demo2.f();
}
}
异常信息: Test class should have exactly one public zero-argument constructor
错误原因: @Test方法所在类中,不能存在有参数构造函数,无参构造可以存在
解决方案: 把有参构造器去掉,使用set方法初始化变量
或者不要使用@Test注解,使用main方法执行.
或者在另外一个类中使用@Test方法