2 Minutes To Code (β Version)

JUnit 4.10 - 2 minute tutorial

Overview of JUnit testing framework

JUnit is the most widely used testing framework for java applications.

Although, immensely helpful, a testing framework is nevertheless, incomplete without a mocking framework like Mockito or Easymock.

How a testing framework is used in practical scenarios is, you call your applicatipn api and then check whether the result of this matches the expected result. However, if you application internally depends on external api or db etc, then to test such api, you will need to make sure that all such services are also up and running. This is very tiresome and unnecessary if all you want to test is the correctness of your api with the assumption that external services will behave properly.

This is where a mocking frameworks steps in. You can generates clones for the classes of external services, wire them to behave in the correct way, and then subsctitue these objects in place of the actual objects objects in you application. You should learn atleast one of the mocking framworks Mockito or Easymock.

This also requires, that you design you application in such a way that substituting a mock object in place of the actual object is easy.