Integration testing of service and DAO layers

We have developed a DAO layer, a service layer, and one unit testing. Let's carry out integration testing of the Ch05_Declarative_Transaction_Management application step by step, as follows:

  1. Create the com.packt.ch05.service.integration_tests package.
  2. Create the JUnit test case TestBookService_Integration by considering BookServiceImpl as the class under test. Select all of its methods to test.
  3. Declare the data member of type BookService, annotate it by the @Autowired annotations, as shown in the following code snippet:
        @RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration("classpath:connection_new.xml")
public class TestBookService_Integration
{
@Autowired
BookService bookService;
}
  1. Let's test the addBook() method, as we did in the JUnit testing earlier. You can refer to the following code:
        @Test 
public void test AddBook() {
// Choose ISBN which is not there in book table
Book book = newBook("Book_Test", 909098L, "Test
Publication", 1000, "Test Book description", "Test
author");
boolean flag=bookService.addBook(book);
assertEquals(true, flag);
}
  1. You can run the test case, which will now run successfully.
All other test methods from BookService can be referred from the source code.

Both the layers developed by us are working as we want them to. We developed controllers, services, and DAOs separately, and tested them as well. Now, we will combine them into a single application so that we have one complete application, and then, using integration testing, we will check if it is working as per expectation.

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

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