reset password

Testing

There are two popular Java testing frameworks: JUnit and TestNG. There was a time when TestNG was considered technically superior, but these days these two are pretty much the same. In this section we will describe how to use TestNG to test database access.

1. Add the following dependencies:

  • org.testng:testng
  • org.springframework:spring-test

and set the scope of both dependencies to test.

2. Create the following folders:

  • src/test/java
  • src/test/resources

then right click on the project and select Maven -> Update Project.... The testing code will be placed under src/test/java, which mirrors the structure of src/main/java, and the resource files used during testing will be placed under src/test/resources.

3. 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.

4. Create some test cases, e.g.

This page has been viewed 5760 times.