Junit to test Spring service and DAO layer

xyz picture xyz · Dec 22, 2011 · Viewed 44k times · Source

I am working on a Spring application (Spring 3.0) and following layered architecture i.e. Controller -> Service -> DAO layers.

I want to write unit test cases for service and DAO layer using Junit.
I checked Spring official site and also tried many other sites but couldn't figure out an easy and simple way of doing it.

Can anybody provide me some helpful resources ?


EDIT :
Looks like Mockito is the good option. Any good link to use it in Spring.

Thank you Alex for suggesting it.

Answer

Alex Barnes picture Alex Barnes · Dec 22, 2011

In terms of resources the Spring documentation on testing is very good. This can be found here.

When you test your service layer you will want to use a mocking library such as Mockito to mock your DAOs and therefore your domain layer. This ensures that they are true unit tests.

Then to integration test your DAOs against a database you can use the Spring transactional test utilities described in that reference documentation.