DevLabs: Code Contracts

 

Code Contracts

Lots of fixes! Our new release has been upgraded to work with Visual Studio 2010 Beta 2. (Of course, it also works with Visual Studio 2008, but this is a great time to download the new beta and get started with it.) There are lots of other improvements: be sure to check out the release notes. And keep using the forum to tell us what you think: many of the fixes were in response to your comments.

Code Contracts provide a language-agnostic way to express coding assumptions in .NET programs. The contracts take the form of pre-conditions, post-conditions, and object invariants. Contracts act as checked documentation of your external and internal APIs. The contracts are used to improve testing via runtime checking, enable static contract verification, and documentation generation. Code Contracts bring the advantages of design-by-contract programming to all .NET programming languages. We currently provide three tools:

  • Runtime Checking. Our binary rewriter modifies a program by injecting the contracts, which are checked as part of program execution. Rewritten programs improve testability: each contract acts as an oracle, giving a test run a pass/fail indication. Automatic testing tools, such as Pex, take advantage of contracts to generate more meaningful unit tests by filtering out meaningless test arguments that don’t satisfy the pre-conditions.
  • Static Checking. Our static checker can decide if there are any contract violations without even running the program! It checks for implicit contracts, such as null dereferences and array bounds, as well as the explicit contracts. (VSTS Edition only.)
  • Documentation Generation. Our documentation generator augments existing XML doc files with contract information. There are also new style sheets that can be used with Sandcastle so that the generated documentation pages have contract sections.

Code Contracts comes in two editions:

  • Code Contracts Standard Edition: This version installs if you have any edition of Visual Studio other than the Express Edition. It includes the stand-alone contract library, the binary rewriter (for runtime checking), the reference assembly generator, and a set of reference assemblies for the .NET Framework.
  • Code Contracts VSTS Edition: This version installs only if you have Visual Studio Team System. It includes the static checker in addition to all of the features in the Code Contracts Standard Edition.

Visit the orginal content @ MSDN-DevLabs (Click on Link) to download and Evaluate the Software…

Logo and Content are created, credited  and copy righted by Microsoft. This is just an information sharing post.