问题描述
TestCode:packageemployees_revenue;importorg.junit.Test;importstaticorg.junit.Assert.*;publicclassAverageRatingTest{//@SuppressWarnings("deprecation")@TestpublicvoidtestAverageRating(){AverageRatingemployee_1142=newAverageRating("1142");employee_1142.addRating(25);employee_1142.addRating(25);assertEquals("BadAverageRating",(int)25,(int)employee_1142.getAverageRating());AverageRatingemployee_1241=newAverageRating("1241");employee_1241.addRating(28.50);employee_1241.addRating(32.50);assertEquals("BadAverageRating",(int)30.50,(int)employee_1241.getAverageRating());}}/////////////////////////////////////////UnitCode:/***MasseyUniversityStudentID:11146252*/packageemployees_revenue;/***@authorVictor**/publicclassAverageRating{publicdoubletotalRating=0;publicintnumberOfRatings=0;publicAverageRating(StringAverageRating){}publicdoublegetAverageRating(){returntotalRating/numberOfRatings;}publicvoidaddRating(doublenewRating){totalRating+=newRating;numberOfRatings++;}}TDDtriangualtion的例子或类似于如下代码:@TestpublicvoidtestEquality(){assertTrue(newDollar(5).equals(newDollar(5)));assertFalse(newDollar(5).equals(newDollar(6)));}publicbooleanequals(Objectobject){Dollardollar=(Dollar)object;returnamount==dollar.amount;}