public class PirateShipTest { @Test(dataProvider = "cannons") public void testFireCannonDepletesAmmunition(int ballsToLoad, int ballsToFire, int expectedRemaining) { PirateShip ship = new PirateShip("The Black Pearl"); ship.loadCannons(ballsToLoad); for (int i = 0; i < ballsToFire; i++) { ship.fireCannon(); } assertEquals(ship.getBallsRemaining(), expectedRemaining); } @DataProvider(name = "cannons") public Object[][] getShipSidesAndAmmunition() { // Each 1-D array represents a single execution of a @Test that // refers to this provider. The elements in the array represent // parameters to the test call. return new Object[] { {5, 1, 4}, {5, 5, 0}, {5, 0, 5} }; }}
<suite name="PirateShip suite" parallel="methods" thread-count="2">
@Test(expectedExceptions = { NoAmmunitionException.class })public void testFireCannonEmptyThrowsNoAmmunitionException() { PirateShip ship = new PirateShip("The Black Pearl"); ship.fireCannon();}
Remember to download this episode of Testing on the Toilet and post it in your office.
No comments :
Post a Comment