我的测试:这是它强调萨克斯之后的东西。并坚持认为我有一个try-catch块....但互联网说,来测试异常的正确方法是@Test(expected=IllegalArgumentException.class)
Java:Junit4:异常测试不起作用,坚持尝试catch块:
@Test(expected= XMLClientNotFoind.class)
public void testGetClientFromIP() throws XMLClientNotFound{
...
assertEquals(c, sax.getClientFromIP("101.0.2.01"));
}
与方法,getClientFromIP是在这里:
public Client getClientFromIP(String ip) throws XMLClientNotFound {
...
throw new XMLClientNotFound();
}
而我的例外:
public class XMLClientNotFound extends Exception{
}