小编dev*_*nch的帖子

如何解决期望代码以引发异常的可抛出单元测试用例?

我试图写测试用例这种情况下,在此我期待SQLIntegrityConstraintViolationException,我试图断言使用断言相同的是通过抛出,但我得到断言错误的期待码养Throwable。如何解决这个问题,有人可以帮我解决这个问题。

我正在使用JUnit5.

如屏幕截图所示,该方法在应用异常情况后似乎没有运行

@Test
public void insertUpdateDatatypesizecountValidation() throws Exception {
    id = 0;
    StandAloneConnection standAloneConnection = new StandAloneConnection(
                        propertyFile);
    Connection conn = standAloneConnection.getConnection();
    assertThatThrownBy(() -> called.datas(conn, id))
            .hasMessage("Column 'ID' cannot be null")
            .isInstanceOf(SQLIntegrityConstraintViolationException.class);
}      

Run Code Online (Sandbox Code Playgroud)

java junit junit5

0
推荐指数
1
解决办法
164
查看次数

标签 统计

java ×1

junit ×1

junit5 ×1