Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use JUnit and Hibernate usefully?

I want to use JUnit to test Hibernate code such as insert, update, delete,.. method and transaction management.

But I don't know how to apply unit test for Hibernate usefully and what should I test with Hibernate.

How can I test DAO methods?

Hope that you could give me some guides!

like image 925
Chan Pye Avatar asked Dec 14 '09 08:12

Chan Pye


1 Answers

You can use DBUnit to test DAO Layer. Because you need data to test.
Example : DBUnit xml will insert dummy data to database which is described by you and then you can call assertEquals("myname", userDAO.findById(1).getName()); etc. After test you can delete dummy data with DBUnit. Check detail.

Documents
Hibernate testing with dbunit
DBUnit and Hibernate

like image 167
baybora.oren Avatar answered Sep 25 '22 15:09

baybora.oren