我有一个DAO,它返回一些值,并且如何检查方法抛出特定异常?
If you're using JUnit and you expect a test to throw a specific exception, do this:
@Test(expected = MyException.class)
public throwsExceptionWhenPassedAnIllegalValue() {
[...]
}
If you're using TestNG, similar syntax:
@Test(expectedExceptions = MyException.class)
public void throwsExceptionWhenPassedAnIllegalValue() {
[...]
}
If the exception that you're expecting is not thrown, these test methods will fail.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.