dbunit 断言未正确抛出失败
以下是一个测试用例,用于测试 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
断言是 DBUnit 抛出 AssertionError。
我发现获得确切异常原因的最佳方法是捕获它,例如:-
Assertion is DBUnit throws AssertionError.
What I found the best way to get the exact exception reason was to catch it, for example:-