我是用 JUnit 进行 Java 测试的新手。我必须使用 Java,并且我想使用单元测试。
我的问题是: 我有一个带有一些抽象方法的抽象类。但也有一些方法是不抽象的。我如何用 JUnit 测试这个类?示例代码(非常简单) :
abstract class Car {
public Car(int speed, int fuel) {
this.speed = speed;
this.fuel = fuel;
}
private int speed;
private int fuel;
abstract void drive();
public int getSpeed() {
return this.speed;
}
public int getFuel() {
return this.fuel;
}
}
我想测试 getSpeed()
和 getFuel()
的功能。
与此问题类似的问题是 给你,但它没有使用 JUnit。
在 JUnit FAQ 部分,我找到了 这个链接,但是我不明白作者在这个例子中想说什么。这行代码是什么意思?
public abstract Source getSource() ;