简体   繁体   中英

DBUnit Test Comparison Failure

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 :)

您必须将表名称添加到“ @ExpectedDatabase”中,例如@ExpectedDatabase(值=“ dataset.xml”,表=“ your_table_name”)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM