Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I want to know if the service test classes should use real DAO objects and connect to the database or it should use mock objects to test only the business logic it do?

share|improve this question

2 Answers

up vote 3 down vote accepted

Your test classes shouldn't connect to the database if you are testing only the business logic, you should use mocks instead.

This way is faster since the tests don't open and close connections and database independent ( you can run the tests without any database. )

If you want to test the DAO objects and the connections to the database then you should have other tests doing that.

share|improve this answer

As an alternative to Thanos Papathanasiou answer, I've seen some DAO objects unit test using in memory database such as SQLite. It's very fast and safe testing.

An example of it testing nHibernate (ORM) can be found on Ayende blog post. Check the same method with Django.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.