我想测试一下junit测试中是否存在一个变量。
我有一个叫做动物的抽象类。
public abstract class Animal {
private final int age;
private final int speed;
public Animal (int age,int speed) {
this.age = age;
this.speed = speed;
}
public static void main(String[] args) {
}
@Override
public boolean equals(Object anotherObject) {
if (this == anotherObject) {
return true;
}else {
return false;
}
}
public abstract Animal[] multiply(int n);
private boolean isFaster(Animal a) {
if(this.getSpeed() >a.getSpeed()) {
return true;
}else {
return false;
}
}
private boolean isOlder(Animal a) {
if(this.getAge() >a.getAge()) {
return true;
}
return false;
}
@Override
public String toString() {
return this.getClass()+ "is " + this.getAge() + " years old, is " +this.getSpeed() +" units fast.";
}
public final int getAge() {
return age;
}
public final int getSpeed() {
return speed;
}
}
我想测试一下变量年龄是否存在,以及它是否是私有的和最终的。在junit测试中,我可能如何做到这一点?
1条答案
按热度按时间w51jfk4q1#
您可以按以下步骤进行:
查看字段的文档页以了解更多信息
Field#getName
以及Field#toGenericString
.