Loading

Test Driven Development


In the field of software engineering, there are numerous methodologies and approaches, available, to carry out the software development process. Almost, in all these development model, development is followed by testing, i.e. a fixed pattern or standard is set, to first implement the requirements, in the development phase, to output a build, version or a partially developed or completely developed product, which undergoes through the testing process and subsequently, delivering the final product of desired quality.

However, there also exists, one more type of development approach or model, where testing is followed by the development, i.e. testing drives the development process, and is known by the name of Test Driven Development.

What is Test Driven Development?

It is a specific approach of carrying out the development process, where testing is done first, and its output, decides and drives the development process. It is one of the agile methodologies of software development, where the test cases for a particular code, functionality or feature, is written and executed, before deploying and implementing that code. The basic working of TDD, involves writing the test first, on the basis of specified requirement, and restructuring and improving the code quality, to pass these test.

Abbreviated as TDD, in test driven development, requirements are implemented in the form of test cases, to cover each of the functionality and features. The tests are executed, and accordingly, the code is refactored or improved, on the failure of its corresponding test cases, and subsequently the improved code, and is made to pass through the new test(for other different functionality). Thus, TDD involves the repetition of cycles, until the codes are enhanced, to pass each design test.

Stages of TDD:

The complete process of developing a software product, using the TDD approach, may be seen as repetition of multiple cycles, where each cycle, comprises of following activities, in a subsequent manner:

test driven development stages image


Write/Add Test:

This phase, involves the study and analysis of the requirements and specifications, for each functionality/feature or modified functionality, by the developers, through the usage of use case and user stories, to ensure the complete coverage of each requirement and functionality.

Run all test and check if the new test, fails:

Verify and validating the desired and appropriate working of the test harness suite. The test created in the previous stage, is examined to ensure that it does not get passed, without the availability of the code. Further, it is also evaluated that the test does not passes, always, rather it should fail also, on encountering with specific conditions or circumstances.

Write the code:

During this stage, codes are written, to pass the tests. The emphasize is made on writing the code, in such a manner, that it successfully passes the test, and simultaneously overlooking the quality aspect. However, the quality of the code, is gradually enhanced, after each iteration.

Run tests:

All the developed test cases are executed in this stage, and if the code passes these entire tests, then the code is said to be ready, and is in compliance with the specified requirements and specifications.

Refactor the code:

As the code, has already passed the tests, this stage ensures the cleaning and bringing improvement in the code, adding more functionality and features, removing duplication and many such things, in the direction of enhancing the quality of the code. Thereafter, re-executing the test, to ensure that the code, is still passing the test, after the process of code refactoring.

Repeat:

The whole cycle is repeated, to consider other different requirement/ specification, and accordingly following the previously stated 5 phases, to produce the code of desired quality, fulfilling the specified requirement.

Levels of Test Driven Development:

Test Driven Development, basically, may be carried out, using two different approaches, as mentioned below:

Acceptance Test Driven Development(ATDD):

All teams and individuals, involved in software development, communicates with each other, which enables them to have accurate and detailed knowledge of the product, and subsequently, decides the acceptance criteria from the user's perspective, based on which acceptance tests are created, and similar activities, as applicable in TDD, is being carried out, further, to drive the development process. It is pertinent, to mention that the acceptance test, may be used, to derive the developer tests.

Developer Test Driven Development(Developer TDD):

Actually, it's a test driven development, where unit test or developer test is being created, and subsequently the code is produced, to pass these tests. This already, has been discussed, in detail.

Advantages of TDD:

  • Useful, in developing the high quality codes.
  • Involvement of small number of steps and cycles, enables programmers, to work, at their ease.
  • As programmers, are involved in writing test and also, in a large number, this increases their efficiency and productivity, towards the development of a software product.
  • Restricts the amount of defects.
  • Motivates developers, to perceive and carry out the software development, from a user's point of view.

Disadvantages oF Test Driven Devlopment:

  • Extra efforts and time is required, to create and maintain the test suites.
  • Changing requirements, may results, into increased complexity in creating the test cases.
  • Sometimes, it may imparts, false sense of correctness, in program, due to misinterpretation of the requirements, which leads to generation of incorrect test and the code, which is made to pass, it.

TDD Tools and Frameworks:

Below given, are some of the tools and framework, readily available in the market, for the purpose of test driven development.

  • XUnit frameworks
  • TAP results
  • DBUnit
  • JUnit
  • XUnit.net
  • TestNG
  • Googletest
  • PHPUnit
  • DUNit(Delphi)