How Can Test-Driven Development (TDD) Be Automated?
Posted on Thu, Jan 20, 2011
Since Parasoft is constantly talking about about automating testing, we're often asked: How does automation apply to Test-Driven Development (TDD)?
Most teams automatically run their TDD tests as part of the continuous integration process. But what else can you automate when the process of designing effective tests is necessarily a creative one?
We've figured out several ways that automation can play an even greater role in making TDD a less painful and more valuable process...
Obstacles to Adopting TDD
The key obstacle that development teams face in truly adopting TDD is the time required to build and maintain the required test cases. Without process automation, time constraints allow the TDD practice to become “optional.”
Time constraints stem from two main sources:
- Setting up good tests can be complex: The process of writing a test that effectively verifies a requirement involves both creativity and solid coding/testing skills. The complexity of creating effective unit tests adds to the challenge: setting up the proper initial conditions for realistic unit tests can be difficult and time consuming.
- The test suite has to be kept in sync with the evolving application: Ideally, as each TDD test is created, it is added to a regression test suite, then run regularly against the evolving code base to alert the team when any code base modifications break or change the already-tested functionality. However, in order for this strategy to deliver the desired results, the team needs to keep the test suite in sync with the evolving application; otherwise, the test results will be so noisy that they will be ignored—or the entire test suite will be abandoned.
Considering the compressed nature of today's development schedules and the constant pressure to do more with less, it is not surprising that such tasks tend to get dropped unless TDD tasks are made a natural and non-negotiable part of the team's day-to-day workflow.
That's where automation comes in.
The Role of Automation in TDD
Automation can be a valuable way to make TDD tasks a seamless part of the development workflow. For instance:
- To make tests more valuable— you can use automation to correlate requirements, tasks, code, tests, builds, developers, and artifacts—as well as add coverage tracking, advanced reporting, and runtime error detection during test execution.
- To ensure that TDD practices are maintained—you can use automation to establish an infrastructure that notifies the developer if a unit test is not yet associated with a task or requirement.
- To facilitate unit test development—you use automation to reduce the work required to implement realistic and useful test cases.
- To facilitate unit test suite maintenance—you can use automation to assign each test failure to the responsible developer and distribute it to his IDE to facilitate review and response.
- To remove testing constraints—you can use service virtualization to mock interactions with incomplete or evolving systems or components that are involved in your tests. This helps you write and run tests well before the complete system is ready/available.
- To ensure that manual tasks become a continuous and natural part of the workflow—you can use automation to orchestrate a policy-driven process. In such a process, management expectations are set by defining what practices are required as well as when and how to apply them...then related tasks are then seamlessly integrated throughout the SDLC and unobtrusively monitored for compliance.
TDD Automation in Practice
How have you applied automation to optimize the TDD process? We invite you to share your stories about what worked and what challenges you faced.
***
Image credit: Ryan Holst
To learn more about ways to automate the TDD process, see Parasoft's paper on Test-Driven Development or Parasoft's unit testing information sheet.