为什么你不能在测试中捕获你的异常?有不同的方法可以做到这一点.像注释一样@Test(expected = DataAccessException.class),也需要根据具体情况使用.但我的建议是以下方式.
public class TestCase{
    @Test
    public void method1_test_expectException () {
     try{
     // invoke the method under test...
     Assert.fail("Should have thrown an exception"); 
     // This above line would only be reached if it doesnt throw an exception thus failing your test. 
                }
     catch(<your expected exception> e){
       Assert.assertEquals(e.getcode(), somce error code);
     }
 }
| 归档时间: | 
 | 
| 查看次数: | 3631 次 | 
| 最近记录: |