Java 单元测试测试异常

在单元测试中总会涉及到Exception的测试,测试的范例如下:


public void testGetUserNotDefined(){
TestRequest req = new TestRequest("test not Defined");
try{
contr.getUser(request);
fail("An exception should be raised if the request handler has not been defined");
}catch (Runtimeexception exception){
assertTrue(true);
}
}

你可能感兴趣的:(Java 单元测试测试异常)