Phase 1 - Unit testing DAO Unit testing by JUnit

Now, it's time to write the actual test case. We will start unit testing the DAO layer. The following are the general steps to write an annotation-based test case:

  1. Create a class; the name of the class is given as XXXTest. XXX will be replaced by the name of the class which we want to test.
  2. Create the setUp() and testDown() methods to initialize the data we need, and release the resources used by us, respectively.
  3. The test methods where we will write testing logic will be named as testXXX. The XXX can be replaced by the name of the method from the DAO class which we want to take under testing.
  4. The method that the test runner should recognize needs to be annotated by @Test.
  5. Use the assertXXX() methods as per the data under test to compare the values.

Let's write the tests for the DAO layer that we developed in the Chapter 3, Accelerate with Spring DAO. We will use Ch03_JdbcTemplates as the base project. You can create a new project, or use Ch03_JdbcTemplates by adding only the test package. Let's follow these steps.

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

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