我需要将expected = ParseException.class添加到Junit方法,但即使将它添加到方法后,throwing行显示“未处理的异常类型ParseException”消息,但我无法运行测试。为什么我不能在JUnit中定义期望的ParseException?
单位测试
import java.text.ParseException;
@Test (expected=ParseException.class)
public void testConvertDate() {
String date = "Tue 3434 20 23:33:44 EST 2014";
MyDate mydate = new MyDate();
Date result = instance.convertDate(date); //this line shows the message
}
方法
import java.text.ParseException;
public Date convertDate(String d) throws ParseException {
....
}
只是在黑暗中拍摄。确保你的方法抛出的“ParseException”和你的测试期望的“ParseException”是一样的 – Susie 2014-10-09 22:25:49
@Susie它们是一样的。 – Jack 2014-10-09 22:46:20