The D language has one of the most integrated unit testing approaches. Programming language designers should take notes.

Inline Unit Tests

In D there is syntax for unit tests, not just some annotations or nameing conventions.

There is no support for advanced testing, though. No setup or teardown routines. No mock objects. At least, so far the standard library does not provide it.

Nevertheless, writing your unit tests right into your code requires less motivation than setting up a testing framework.


Additionally, unit tests can also serve as usage examples for APIs. The newest D release (2.063) integrates unit tests into their ddoc tool. Which means the generated API documentation now shows unit tests as examples.

Previously, examples would be written into the comment string, which means there is the danger, that they would get out of date when the code evolves. Now, the unit tests get executed often of course, which means the examples are checked as well.

© 2013-05-26