我修改了測試使用以前的考題,我就不能得到100%的覆蓋率即將舉行的這一週,我的計劃是:Java軟件測試
public int computeInsurance(boolean SportsEquipment, boolean MusicEquipment)
{
int insurance;
if(SportsEquipment == true && MusicEquipment==true)
insurance = 20;
else if((SportsEquipment == true && MusicEquipment == false)||(SportsEquipment == false && MusicEquipment == true))
insurance = 10;
else
insurance= 5;
return insurance;
}
}
我使用下面的測試情況:
public class Lab5CarTest {
@Test
public void testComputeInsurance() {
Lab5Car t = new Lab5Car();
int result = t.computeInsurance(true, true);
assertEquals(20,result);
int i = t.computeInsurance(true,false);
assertEquals(10,i);
int u = t.computeInsurance(false,false);
assertEquals(5,u);
}
}
但是我錯過了3個分支中的8個,其他的如果我的代碼行!
在哪裏'假,TRUE'情況? –
add「int i = t.computeInsurance(false,true);」並看看你得到了什麼 – bobah
啊,我應該看到那個!但是,在我添加該行後,仍然缺少8行中的2個分支,如果其中有一行代碼! – user1816464