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 objects for testing. To avoid using the actual data, the test class mocked DepartmentDao and substituted some dummy lists of departments instead into the service transaction readEmployees() to check whether the process of retrieval does not encounter any exceptions or performance problems. This can be effective, especially if the resources are not readily available to provide some test data to service layer.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.83.151