Posted By:
Paul_Hunnisett
Posted On:
Monday, December 20, 2004 04:04 AM
I'm just experimenting with easy mock (using the class extensio as well) to see if it's robust enough for us to use for our testing. I wrote the following test in my test class: public void testAttack(){ Player player = new Player(20); Orc orc = new Orc(20); player.setDie(die); die.roll(); //An isntance of Die.class - my mock object control.setReturnValue(14); control.setReturnValue(8); control.setReturnValue(10); control.setReturnValue(5); control.setReturnValue(14); control.setReturnValue(3); control.setReturnValue(17); control.setReturnValue(14); control.replay(); player.attack(orc); System.out.pri
More>>
I'm just experimenting with easy mock (using the class extensio as well) to see if it's robust enough for us to use for our testing.
I wrote the following test in my test class:
public void testAttack(){
Player player = new Player(20);
Orc orc = new Orc(20);
player.setDie(die);
die.roll(); //An isntance of Die.class - my mock object
control.setReturnValue(14);
control.setReturnValue(8);
control.setReturnValue(10);
control.setReturnValue(5);
control.setReturnValue(14);
control.setReturnValue(3);
control.setReturnValue(17);
control.setReturnValue(14);
control.replay();
player.attack(orc);
System.out.println("Player: " + player.getHealth());
System.out.println("Orc: " + orc.getHealth());
assertTrue("Player should have been hurt and Orc Killed",((player.getHealth()== 17))&&(orc.isDead()));
control.verify();
}
It's just an experiment inspired by the chapter on Mock objects in Test Driven development by David Astels.
The Die class normally returns a random number, but here I was expecting the above returns from the mock object.
Sometimes it returns as expected, but jsut as often it return a random number - the test therefore fails every time...
Can anyone suggest why it is not returning as expected every time...?
<<Less