Loose coupling and testability

Through DI, Spring brings loose coupling between classes. While loose coupling is beneficial for application maintainability in the long run, the first benefits are realized with the testability that it brings in. 

Earlier versions of Java EE applications were very difficult to unit test. In fact, it was difficult to test code outside of the container. The only way to test code was to deploy them in a container.

DI enables unit testing by making it easy to replace the dependencies with their mocks. We do not need to deploy the entire application to unit test it.

Simplifying unit testing has multiple benefits:

  • Programmers are more productive
  • Defects are found earlier so they are less costly to fix
  • Applications have automated unit tests, which can run in Continuous Integration (CI) builds, preventing future defects
CI involves running all of the automated tests and deployments as soon as the code is committed to version control. This would ensure that any broken test or feature is found and reported immediately.
..................Content has been hidden....................

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