Be Assured, Take a Test Drive

In the previous chapters, we discussed in depth about extracting data from HTTP requests, developing business logic, handling data with database layers, and also how to render web pages to show the results. Application development is a lengthier, time-consuming, and expensive process. The development depends upon the requirements collected from the clients and market requirements. However, what if, after the completion of the work, something goes wrong, and everything collapses? The collapse is not because of an incorrect solution, but because it's based on wrong assumptions that developers made before starting the work. This collapse occurs just before the date of delivery to the client. Now nothing can be recovered! Let's not go into the details of why and what went wrong. However, what I am interested in is how this can be avoided. Is there something that can be done to prevent this last moment collapse? We all know that "prevention is better than cure". This phrase is applicable to application development as well. The situation of failure can be avoided with a bit of extra efforts taken by developers step by step. Cross-checking that the code developed is according to the requirements can help assure developers regarding correct working of the code. This cross-checking is called testing of the application. Also, nowadays, Test-driven Development (TDD) is a hot topic in discussion. TDD is a process of software development which is based upon test first. In TDD, even a small piece of the developed code is tested in test cases. Any further development in the code will be tested by writing a new testing case. TDD facilitates developers to focus on writing error-prone code, instead of discovering problems after the development completes. In this chapter, we will discuss testing with the help of the following points:

  • Why testing?
  • Problems in testing Spring Controllers
  • Mock testing
  • Spring TestContext Framework
  • Using Mokito to test Spring Controller
  • Introduction to Spring Controller testing using Arquillian
..................Content has been hidden....................

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