Как использовать assertEquals, чтобы узнать, правильно ли указано сообщение об исключении? Тест проходит, но я не знаю, попадает ли он в правильную ошибку или нет.junit testing - assertEquals for exception
Тест Я бегу.
@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