ALERT

[FREE DEMO] Deploy Your Enterprise Cloud in Minutes

Test Driven Development (TDD)

Definition - What does Test Driven Development (TDD) mean?

Test driven development (TDD) is an software development approach in which a test is written before writing the code. Once the new code passes the test, it is refactored to an acceptable standard.

TDD ensures that the source code is thoroughly unit tested and leads to modularized, flexible and extensible code. It focuses on writing only the code necessary to pass tests, making the design simple and clear.

Techopedia explains Test Driven Development (TDD)

TDD enables the programmer to take small steps while writing software. The test is written before testing the functionality and ensures that the application is suitable for testability. Testing on a small amount of code is performed to trap errors that occur in the tested code. Then the functionality is implemented. This is referred to as "red green refactor" where red means fail and green shows a pass. These steps are then repeated. The first goal of a programmer is to focus on the task at hand and to pass it.

The different steps involved in a test driven development cycle are:

  • Add a test: Every new feature in TDD starts with a test which has to fail as it is put into effect before any features are implemented. The essential requirement to write a test before feature implementation is a clear understanding of the requirement by the developer. This is accomplished through user stories and use cases. Hence a developer understands the requirement before writing the program code.
  • Run all tests and check if the new code fails: This ensures correct working of the test harness and that the new test does not pass by mistake without any new code. This step also tests the test and eliminates the possibility that the new test always passes.
  • Write code: The next step that follows is writing code that clears the test. The new code is not perfect but is later modified as per the requirements. It’s merely designed for testing and does not enclose other functionalities.
  • Run automated tests: If every test case produced easily passes the test, it implies that the code meets all required specifications. Hence the final step of the cycle can be started.
  • Refactor code: This is similar to removing duplication. A refactoring does not damage any existing functionality and helps in removing duplication between production and test codes. The code is now cleaned as required.
  • Repeat: The cycle is repeated as in the previous cases with a new test. The essential requirement is that the size of the steps should be small, with around 1 to 10 edits between every test run. If new code does not satisfy a new test, the programmer should perform additional debugging. Continuous integration provides revertible checkpoints.

Techopedia Deals

Connect with us

Techopedia on Linkedin
Techopedia on Linkedin
Tweat cdn.techopedia.com
"Techopedia" on Twitter


'@Techopedia'
Sign up for Techopedia's Free Newsletter!

Email Newsletter

Join thousands of others with our weekly newsletter

Resources
The 4th Era of IT Infrastructure: Superconverged Systems
The 4th Era of IT Infrastructure: Superconverged Systems:
Learn the benefits and limitations of the 3 generations of IT infrastructure – siloed, converged and hyperconverged – and discover how the 4th...
Approaches and Benefits of Network Virtualization
Approaches and Benefits of Network Virtualization:
Businesses today aspire to achieve a software-defined datacenter (SDDC) to enhance business agility and reduce operational complexity. However, the...
Free E-Book: Public Cloud Guide
Free E-Book: Public Cloud Guide:
This white paper is for leaders of Operations, Engineering, or Infrastructure teams who are creating or executing an IT roadmap.
Free Tool: Virtual Health Monitor
Free Tool: Virtual Health Monitor:
Virtual Health Monitor is a free virtualization monitoring and reporting tool for VMware, Hyper-V, RHEV, and XenServer environments.
Free 30 Day Trial – Turbonomic
Free 30 Day Trial – Turbonomic:
Turbonomic delivers an autonomic platform where virtual and cloud environments self-manage in real-time to assure application performance.