Unit Testing .NET Applications Using Code Contracts

CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

As a developer is going through the testing phase of application development, they will typically take the app through unit testing, where several small tests validate each unit of code. Each application will typically require hundreds or even thousands of tests to successfully validate the code.


Like the application itself, the success of the unit tests depends on how they are written. Code Contracts, available since the debut of .NET framework 4, go hand in hand with unit testing. They enable the developer to define preconditions, postconditions and class invariants, and require code to be embedded in a developer’s existing classes.

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read