@Rule
public final ExpectedException exception = ExpectedException.none();
@Test
public void doStuffThrowsParseException() {
TestException foo = new TestException();
exception.expect(ParseException.class);
foo.doStuff("haha");
}
主
Date submissionT;
SimpleDateFormat tempDate = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy");
public void doStuff(String time) {
try {
submissionT=tempDate.parse(time);
}
catch (Exception e) {
System.out.println(e.toString() + ", " + time);
}
}
结果为java.text.ParseException: Unparseable date: "haha", haha
。
虽然抛出ParseException,但测试失败。为什么呢?