Unit Testing

This lesson explains how unit testing can be used for catching bugs and how to activate the unit tests. Then, it further explains the unit test blocks in detail.

Unit testing for catching bugs #

  • Since programs are written by programmers and D is a compiled language, the programmers and the compiler will always be there to discover bugs. Those two aside, the earliest and the most effective (partly because it was the earliest) way of catching bugs is unit testing.
  • Unit testing is an indispensable part of modern programming. It is the most effective method of reducing coding errors. According to some development methodologies, code that is not guarded by unit tests is buggy code. Unfortunately, the opposite is not true: Unit tests do not guarantee that the code is free of bugs. Although unit tests are very effective, they can only reduce the risk of bugs.
  • Unit testing also enables refactoring the code (i.e. making improvements to it) with ease and confidence. Otherwise, it is common to accidentally break some of the existing functionality of a program when adding new features to it. Bugs of this type are called regressions. Without unit testing, regressions are sometimes discovered as late as the quality assurance (QA) testing of future
...