Search code examples
visual-studiounit-testingcode-contracts

Using Code Contracts in unit tests


Do you think it is advisable to use Code Contracts inside your unit tests? I don't think it is since it is like creating unit tests to test your unit tests. Therefore I would not activate the Code Contracts Static Checking nor the Runtime Checking for a Unit Test project.

To clarify, I would like to know, in particular, if you would write Code Contracts code inside your unit tests.


Solution

  • I think it's a good idea to enable Code Contracts for unit tests, then any contract failures can be caught when the tests are run.

    However it's usually not useful to do any contract checking in the test methods themselves, except in helper methods used by the test methods.