Say you have this class:
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;
}
}
and we want to test it
public class MyObjTest
{
@Test
public void test5AddFive_equals10()
{
MyObj obj = new MyObj(5);
obj.addFive();
assertEquals(10, obj.getX());
}
}
The question is - is ok that you're calling a getter method in order to test it? What if your getter method was (somehow) broken?
Aucun commentaire:
Enregistrer un commentaire