假设你有这门课程:
public class MyObj
{
private int x;
public MyObj(int x)
{
this.x = x;
}
public void setX(int x)
{
this.x = x;
}
public int getX()
{
return this.x;
}
public void addFive()
{
this.x = this.x +5;
}
}
我们想测试它
public class MyObjTest
{
@Test
public void test5AddFive_equals10()
{
MyObj obj = new MyObj(5);
obj.addFive();
assertEquals(10, obj.getX());
}
}
问题是 - 您是否可以调用getter方法来测试它?如果你的getter方法(以某种方式)被破坏怎么办?