D has built-in support for contract programming and unit testing. D's contract programming implementation consists of two loosely related features: invariants and function contracts. None of these features would be as useful as they are without the assert expression.
Before we dig into the details, I'd like to point out that all of these features, except unit tests, are enabled by default. Passing
-release to the compiler will disable asserts, function contracts, and invariants. Typically, you'll want to leave that flag out during development and use it when you are ready to start testing the release version.
assert expression evaluates a Boolean expression and throws an
AssertError when the ...