DBUnit Test Comparison Failure

拈花ヽ惹草 提交于 2020-01-25 05:18:10

问题


I have a problem with a db unit test which tests if data is persisted correctly. Therefore I created an sample db with my data and tried to compare the setup and the expected data. The id generation and everything else should be managed by hibernate

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DbUnitTestExecutionListener.class })
@DatabaseTearDown("empty.xml")
public class UserDaoTests {

    @Autowired
    UserAdminDao userDao;

    @Test
    @DatabaseSetup("db-setup.xml")
    @ExpectedDatabase("db-expected.xml")
    public void testPersistUser(){

        User user = new User();

        user.setUserId("user2");
        user.setName("test2");
        user.setEmail("user2@email.com");
        user.setLocked(false);
        user.setEnabled(true);
        user.setVersion(0);
        user.setPassword("asdfasdf");

        userDao.persist(user);

    }

}

And my setups are:

<dataset>       
    <user id="1" userId="user1" name="test1" email="user1@email.com" locked="0" enabled="1" version="0" password="asdfasdf" /> 

</dataset>

and the same with user id=2 underneath:

<user id="2" userId="user2" name="test2" email="user2@email.com" locked="0" enabled="1" version="0" password="asdfasdf" />

But I'm getting an Comparison error:

junit.framework.ComparisonFailure: row count (table=user) expected:<[2]> but was:<[1]>

Not sure where my mistake is. thx for any help :)


回答1:


You have to add table name to "@ExpectedDatabase" Something like this @ExpectedDatabase(value = "dataset.xml", table = "your_table_name")



来源:https://stackoverflow.com/questions/21909399/dbunit-test-comparison-failure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!