Creating tests for DAO and service layers
Integration testing is also needed to validate and verify the results of each repository and service method. All repository transactions are dependent on the java.sql.DataSource
package configured by one of the context definitions. Likewise, the services will not be working without the repository beans injected into the container. Although it needs the full configuration of Spring TestContext, this recipe does not need the creation of MockMvc
just to execute these test cases.
Getting ready
Open the Maven project ch03-jdbc
and add the following unit test cases for service and DAO layers.
How to do it...
Let us test the service and DAO layers by performing the following steps:
- Add the Spring Test module, JUnit 4, and Mockito Maven dependencies into the project's
pom.xml
file. - Inside
src/test/java
, create theorg.packt.dissect.mvc.test
package and add inside it a Spring TestContext class:
import static org.junit.Assert.*; @RunWith(SpringJUnit4ClassRunner...