Search⌘ K
AI Features

Test-Driven Development

Explore test-driven development in D to understand how writing unit tests before implementing code helps identify bugs early. Learn to create tests that catch errors and apply fixes effectively, enhancing software reliability.

Test-driven development

Test-driven development (TDD) is a software development methodology that prescribes writing unit tests before implementing functionality. In TDD, the focus is on unit testing. Coding is a secondary activity that makes the tests pass.
In accordance with TDD, the ordinal() function below can first be implemented intentionally incorrectly:

D
import std.string;
string ordinal(size_t number) {
return ""; // ← intentionally wrong
}
unittest {
assert(ordinal(1) == "1st");
assert(ordinal(2) == "2nd");
assert(ordinal(3) == "3rd");
assert(ordinal(10) == "10th");
}
void main() {
}

The function should ...