[英]initializationError: Test class should have exactly one public zero-argument
我正在初始化錯誤。
java.lang.Exception: Test class should have just a public zero-argument constructor 我的代碼是(這是 Java Programming Interview Exposed 中的一個例子):
import org.junit.*;
import static org.junit.Assert.*;
public class Complex {
private final double real;
private final double imaginary;
public Complex(final double r, final double i) {
this.real = r;
this.imaginary = i;
}
public Complex add(final Complex other) {
return new Complex(this.real + other.real,
this.imaginary + other.imaginary);
}
// hashCode omitted for brevity
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Complex complex = (Complex) o;
if (Double.compare(complex.imaginary, imaginary) != 0) return false;
if (Double.compare(complex.real, real) != 0) return false;
return true;
}
@Test
public void complexNumberAddition() {
final Complex expected = new Complex(6,2);
final Complex a = new Complex(8,0);
final Complex b = new Complex(-2,2);
assertEquals(a.add(b), expected);
}
}
任何幫助,將不勝感激。
錯誤准確地說明出了什么問題。 您的類沒有“恰好一個公共零參數構造函數”。
但黃金法則是在商業課程之外進行測試。 因此,創建名為public class ComplexTest
新類並將您的測試方法放在那里。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.