开发者

Duplication between xml dataset file and test method code

I have some unit tests for my DAOs (implemented using JPA). I thought that it wou开发者_如何学运维ld help to test every CRUD method separately, e.g. to test the findAll() method, I populate the database using DbUnit and then in the test I only call the DAO's findAll() method.

This seems as a better approach than populating the database using create() method from the same class (tested methods are more isolated).

The only problem is that I have duplicate test data. I have the XML dataset for DbUnit and I also need to create some entities manually to use as expected results, so I have a subset of this dataset hardcoded in the test classes.

I don't have much experience with testing, but it looks to me that these test could break easily when changed. Is there any way to avoid this kind of duplication that is worth the effort?


I usually prefer to setup the test database with JPA as well. This a type-safer approach and also tests the JPA annotations at the same time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜