【发布时间】:2010-08-17 09:11:22
【问题描述】:
以下是一个测试用例,用于测试 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 返回时,它不会作为测试用例失败而抛出。
我想我在这里缺少一些东西。请纠正我或让我知道解决方案。 预先感谢。
【问题讨论】:
-
我只能说,让你的例子越来越简单,直到你发现发生了什么。
-
@Daniel:感谢您的反馈。我添加了一些 cmets 以使其更易于理解,并且在此示例中我不能再简单了,并且错误仍然存在。如果它抛出任何错误我可以做一些谷歌搜索,但它没有抛出任何失败/错误:(
标签: java maven junit assert dbunit