How it works...
It is ideal to run tests against all repositories and service methods before applying them to any request-response transactions. To test all these components, we need to load all the necessary context definitions to Spring TestContext in order to access every autowiring detail of each bean. To test the correctness and effectiveness of each method, we have to execute the actual methods or perform isolated testing using mocking.
Although quite risky, TestDepartmentDao executes the actual repository transactions that deal with the actual database schema. This can be effective, as long as the data involved is not live. On the other hand, TestDepartmentService prefers to use the @Mock objects to be injected into some @InjectMock ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access