我需要將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