Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在使用异常映射器时使用 Junit4 测试抛出的异常?
测试抛出的异常,预期从执行。请用 :
@Test(expected=<ExpectedException>.class) public void testThrownException() { // Your test code that throws the expected exception }
如果您的代码抛出预期的异常,测试将通过,而断言失败和代码抛出的任何其他异常则失败。