如何使用的assertEquals,看是否異常消息是正確的? 測試通過,但我不知道它是否符合正確的錯誤。的JUnit測試 - 的assertEquals異常
我正在運行的測試。
@Test
public void testTC3()
{
try {
assertEquals("Legal Values: Package Type must be P or R", Shipping.shippingCost('P', -5));
}
catch (Exception e) {
}
}
的方法進行測試。
public static int shippingCost(char packageType, int weight) throws Exception
{
String e1 = "Legal Values: Package Type must be P or R";
String e2 = "Legal Values: Weight < 0";
int cost = 0;
if((packageType != 'P')&&(packageType != 'R'))
{
throw new Exception(e1);
}
if(weight < 0)
{
throw new Exception(e2);
}
if(packageType == 'P')
{
cost += 10;
}
if(weight <= 25)
{
cost += 10;
}
else
{
cost += 25;
}
return cost;
}
}
感謝您的幫助。
謝謝!簡單,幫助了很多 – Meowbits 2012-04-13 21:06:26