dbunit 断言未正确抛出失败

发布于 2024-09-15 04:21:03 字数 1541 浏览 5 评论 0原文

以下是一个测试用例,用于测试 org.dbunit.Assertion.assertEquals(ITable a, ITable b) 的工作情况

@Test
public void testAssertion() {
    try {
        //Creating actual table with 2 columns
        DefaultTable actual = new DefaultTable("table_name",
                new Column[] { new Column("col1", DataType.INTEGER),
                        new Column("col2", DataType.VARCHAR) });
        actual.addRow(new Object[] { 1, "ABCD" });
        actual.addRow(new Object[] { 2, "BABCD" });
        actual.addRow(new Object[] { 3, "CCGF" });

        //Creating expected table with same 2 columns
        DefaultTable expected = new DefaultTable(expected
                .getTableMetaData());
        expected.addRow(new Object[] { 1, "ABCD" });
        expected.addRow(new Object[] { 2, "BBCD" });

        // Check the actual vs expected
        Assertion.assertEquals(actual, expected);
        //This should return a test failure since actual & expected are different.
        //But its not throwing any test case failure.
    } catch (DataSetException e1) {
        e1.printStackTrace();
    } catch (DatabaseUnitException e) {
        e.printStackTrace();
    }
}

,这里两个 DefaultTable 的值都不匹配,但 JUnit 仍然没有使上述测试用例失败。我从 eclipse 运行它,它会导致 0 个错误和 0 个失败,在测试用例下进行无根测试,如下所示,

    testAssertion [Runner: JUnit 4]
[+] Unrooted Tests [Runner: JUnit 4]

我调试了 DBUnit API,它根据需要抛出数据不匹配异常,但最后从 SpringJUnit4ClassRunner 返回时,它是不作为测试用例失败而抛出。

我想我在这里缺少一些东西。请纠正我或让我知道这个问题的解决方案。 提前致谢。

Following is a test case which tests the working of org.dbunit.Assertion.assertEquals(ITable a, ITable b)

@Test
public void testAssertion() {
    try {
        //Creating actual table with 2 columns
        DefaultTable actual = new DefaultTable("table_name",
                new Column[] { new Column("col1", DataType.INTEGER),
                        new Column("col2", DataType.VARCHAR) });
        actual.addRow(new Object[] { 1, "ABCD" });
        actual.addRow(new Object[] { 2, "BABCD" });
        actual.addRow(new Object[] { 3, "CCGF" });

        //Creating expected table with same 2 columns
        DefaultTable expected = new DefaultTable(expected
                .getTableMetaData());
        expected.addRow(new Object[] { 1, "ABCD" });
        expected.addRow(new Object[] { 2, "BBCD" });

        // Check the actual vs expected
        Assertion.assertEquals(actual, expected);
        //This should return a test failure since actual & expected are different.
        //But its not throwing any test case failure.
    } catch (DataSetException e1) {
        e1.printStackTrace();
    } catch (DatabaseUnitException e) {
        e.printStackTrace();
    }
}

Here both the DefaultTable's values are mismatched and still JUnit is not failing the above testcase. I am running it from the eclipse and it results in 0 Errors and 0 Failures with an Unrooted Tests under the testcase like as follows,

    testAssertion [Runner: JUnit 4]
[+] Unrooted Tests [Runner: JUnit 4]

I debugged the DBUnit API and it is throwing data mismatch exception as required, but finally when returning from SpringJUnit4ClassRunner it is not thrown as a test case failure.

I suppose something I am missing here. Pls correct me or let me know a solution for this.
Thanks in advace.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安穩 2024-09-22 04:21:05

断言是 DBUnit 抛出 AssertionError。

我发现获得确切异常原因的最佳方法是捕获它,例如:-

try
{
     Assertion.assertEquals( expectedTable, actualTable );
}
catch ( AssertionError e )
{
     logger.error( "Assertion failed with error : " + e.getMessage());
}

Assertion is DBUnit throws AssertionError.

What I found the best way to get the exact exception reason was to catch it, for example:-

try
{
     Assertion.assertEquals( expectedTable, actualTable );
}
catch ( AssertionError e )
{
     logger.error( "Assertion failed with error : " + e.getMessage());
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文