我需要将期望的= ParseException.class添加到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 {
....
}
因为该异常是一个已检查的异常,需要在一个try/catch
块中声明或将其括起来。在方法级别声明它,以允许它由管理JUnit
。
@Test (expected=ParseException.class)
public void testConvertDate() throws ParseException {
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句