Unit testing

When we start to build our application, we have the application divided into a number of submodules. These submodules contain a number of classes or methods that interact together to achieve a certain output.

For the correct output to be generated, all the individual classes and methods need to work correctly, otherwise the results will differ.

Now, when our target is to check the correctness of the individual components of a code base, we usually write tests that target these individual components independently from the other components of the application. This kind of testing, where an individual component is tested independently of the other components, is known as unit testing.

To state this briefly, the following are some features of unit tests:

  • Starts early in the development cycle: Unit testing usually starts early from the development phase itself, and the unit tests are written so as to cover the individual components inside a code base.
  • Isolation of components: Each component is tested in complete isolation from the other components. In case there are some components that may depend upon other components, stubs or fakes can be used to simulate the interaction.
  • Increased automation: Since the unit tests usually cover individual components and are mostly a piece of code trying to mock some method or class, these tests may be easily automated, and can be run again and again over the code quite quickly without manual intervention.

Unit testing allows a developer to detect issues early in their code base and hence enable the developer to quickly fix pieces of code that might be providing an incorrect behavior that can later affect the functionality of the application. But the ability of the unit tests to find all the issues is quite limited. Since unit tests are used to check a component in isolation, they are not able to evaluate all the execution paths that a code may take, hence limiting their scope of finding all the bugs.

To overcome the shortcomings of unit tests, there are additional testing techniques that are used. Let's take a look at one of the techniques that is often used to test the behavior of the application when the different components of the application interact with each other.

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

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