REST API Using Spring and Hibernate4. TestNGIn this step we are going to add some database access code and use TestNG to test it. 1. Add the following dependencies:
and set the scope of both dependencies to test. 2. Copy src/main/webapp/WEB-INF/applicationContext.xml to src/test/resources. This bean configuration file will be used by the testing code to initialize the Spring framework and create beans for data sources, entity manager, and so on. 3. Create a test class as follows and place it under src/test/java/springmvc/model/dao:
In Eclipse, right click the class and select Run As -> TestNG Test. If you have created the database using springmvc-create.sql as described in the previous step, both tests should pass. |
