www.fgks.org   »   [go: up one dir, main page]

DevLabs: Code Contracts


Code Contracts

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. (Premium 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 Premium Edition: This version installs only if you have one of the following: Visual Studio 2008 Team System, Visual Studio 2010 Premium Edition, or Visual Studio 2010 Ultimate Edition. It includes the static checker in addition to all of the features in the Code Contracts Standard Edition.

See more DevLabs projects >


Feedback

Give feedback about Code Contracts in the DevLabs Forums.

RSSURL : http://social.msdn.microsoft.com/Forums/en-US/codecontracts/threads?outputAs=rss | RSS GUID : 6b9c052d-03ce-944a-a3ba-15cc0e95f56f

Code Contracts

Return value contracts for math-related functions.
Is it possible to add result value contracts to the math-related functions (Exp, Sqrt, Abs etc.) ?Possble contract for Exp:Contract.Ensures((Contr... more
Saturday, Feb 12
Minor suggestion: Inline assume
When the verifier fails to prove a postcondition, I often end up breaking a concise return line into an assignment then assumption then return. It mig... more
Saturday, Feb 12
Fixable incompatibility with code analysis (validate parameter before usage)
When a method's preconditions could potentially cause an infinite cycle, code contracts uses an 'insideContractEvaluation' count to prevent infinite r... more
Saturday, Feb 12
Interface methods with contracts need extra assertion?
Hello guys.I've got the following interface:[ContractClass(typeof(ADHelperContract))] public interface IADHelper { IEnumerable<ADGroup>...; more
Friday, Feb 11
Featured Video

Getting Started with Code Contracts in Visual Studio 2008

 

 

 

Get Code Contracts

Code Contracts provide a language-agnostic way to express coding assumptions in .NET programs.

Get Started

Download Code Contracts Standard Edition or Premium Edition.
Read the Code Contracts documentation.


Requirements

  • Development Tools: Visual Studio (for Code Contracts Standard Edition); or Visual Studio 2008 Team System, Visual Studio 2010 Premium Edition, or Visual Studio 2010 Ultimate Edition (Premium Edition)

DCSIMG