Wednesday, November 15, 2017

Why Unit Testing



  • Software development is a Team work nowadays. So once code written by one team member should not get break by other, Junit can prevent it.
  • Agile promotes TDD Test Driven Development. It means write test code first and then write production ready code.
  • A fix done for defect should not introduces new error in code.
  • Mistake is part of human nature. Even a good programmer can write wrong code. But Junit test alerts to fix it timely.
  • TDD (Test Driven Design) helps to make code simple and reusable , it helps in designing of code.
  • Making test cases automates will reduce lot of effort to test code.
  • It helps to understand existing code.
  • Unit testing must be written before writing code and should be maintained through development life cycle.
  • Also it reduces development cost by providing test failure reports.

Unit testing provides below benefits

  • Specification of system : like what should be input and expected output and business conditions.
  • Error Detection : Timely test reports helps to catch defect .
  • Good Design : Individual modules makes easy to test.
  • Save cost and time of project.
  • Test cases itself are documents to describe expectation of code.

Good Unit test cases are 

  • Readable : Follow Java Naming conventions/comments and provides Java Doc as well.
  • Fast : It should uses mock to object to get it finish soon.
  • Independent and Isolated : less complex and easy to test.
  • Correct : Should test exact business logic of code.
  • Repeatable :For random Test data it should produce expected result even it get executed many times.

No comments:

Junit 5 Architecture

Modules in JUnit 5 : •         junit-jupiter-api: This module defines the API that you need to write your tests. •         ...