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!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With