# Increase Automation of Test-Driven Development?

- Canonical URL: https://amund.blog/archive-increase-automation-of-tdd/
- Author: Amund Tveit (https://amund.blog/about/)
- Published: 2008-01-06
- Tags: Programming, AI Systems, Testing, History
- Original Source: amundblog.blogspot.com (https://amundblog.blogspot.com/2008/01/increase-automation-of-test-driven.html)

---

I believe Test-Driven Development (TDD) can be improved through increased automation, and some of these ideas could likely be adapted to [Behavior-Driven Development](http://steve-yegge.blogspot.com/2007/12/codes-worst-enemy.html) (BDD) as well.

[Test-Driven Development](http://en.wikipedia.org/wiki/Test-driven_development) is a *manual* repeated [cycle](http://en.wikipedia.org/wiki/Test-driven_development#Test-Driven_Development_Cycle) of writing and running tests, writing the least amount of code to make the tests pass, and finally [refactoring](http://www.refactoring.com/) code (and tests) to make them shine. Writing tests produces the crucial "side effect" of simultaneously designing the [API](http://lcsd05.cs.tamu.edu/slides/keynote.pdf).

## Automating the Coding Part?

The word *automated* is often mentioned alongside TDD, yet it usually refers only to automated unit test execution (where the tests themselves are still *manually* written) or automated refactoring (still *manually* triggered by the developer in an IDE).

Writing implementation code in TDD follows a greedy approach: writing just enough to make tests pass, meaning each TDD cycle typically adds only one or a few short methods called by the new test — small increments of code. These small increments could potentially be induced automatically using machine learning, such as [inductive logic programming](http://en.wikipedia.org/wiki/Inductive_logic_programming), [program synthesis](http://en.wikipedia.org/wiki/Program_synthesis), or [genetic programming](http://en.wikipedia.org/wiki/Genetic_programming).

There are at least two challenges with this:
1. **Readability of induced code** — which can still be *manually* cleaned up during the refactoring step of the TDD cycle.
2. **Scalability of induction** — where [mocks](http://www.devx.com/Java/Article/34990) could potentially be used to prune the search space for the learning algorithm.

## Towards API-Driven Design (ADD?)

A hot topic in software testing research is building tools that automatically generate unit tests from code — for example, taking legacy code with low coverage and raising it to high or full coverage. In their simplest form, such tools permute inputs (including corner and extreme values), which often yields huge volumes of variable-quality tests. Smarter tools, such as [DSD-Crasher](http://www.cc.gatech.edu/%7Ecsallnch/dsd-crasher/index.html), promise much higher-quality test generation.

Tools like this could fill in missing test cases inside TDD itself: if a developer writes one test with sample input values, the tool could generate the corner-case variants automatically. That nudges development toward **API-Driven Design**, where the developer defines the contract once without manually writing repetitive test variants.

## Remarks on Code Size

I agree with Steve Yegge that [size is code's worst enemy](http://steve-yegge.blogspot.com/2007/12/codes-worst-enemy.html), and believe size becomes easier to manage if much of the boilerplate implementation and test permutation is offloaded to the computer so the programmer can focus on API-driven design. I don't think [everybody should be afraid of a little typing](http://blog.borud.no/2007/12/why-is-everyone-so-afraid-of-bit-of.html) when it improves readability — yet developers should spare their fingers whenever the computer is eager to fill in.
