JUnit异常处理测试

时间:2016-08-05 09:22:46

标签: java junit

在DAO课程中

catch (Exception e) {

        throw new DaoException(e);
}

在Junit Class中

@Test
public void testClass() throws DaoException {
    try {
        doThrow(Exception.class).when(testDAO).getTestData();
        testDAO.getTestData();
    } catch (Exception e) {
        e.printStackTrace();

    }

}

无法覆盖DaoException。请您帮我介绍JUNIT中的DAOException。

1 个答案:

答案 0 :(得分:2)

您不应将其包含在JUnit中的try catch块中。 看起来你想验证是否抛出了DaoException类。

由于您已经在使用JUnit 4,因此以下是它的语法:

$('a.list-group-item').click(function () {
    var actives = $(this).closest('ul').find('a.active');
    actives.not($(this)).removeClass('active');
});

如果它抛出DaoException,上面的代码段将通过测试。