此问题已在此处有答案:
How do you assert that a certain exception is thrown in JUnit tests?(35个回答)
2天前关闭。
如何检查Junit中@Test
字段中的方法是否抛出异常?
例如:
@Test
public void testGenerateInvalidStudentData() {
//TODO: check does studentIdGenerator.generate(null,2);
// throw IllegalArgumentException or no.
}
1条答案
按热度按时间lokaqttq1#
Use @Test(expected = IllegalArgumentException.class)