Showing posts with label CodeContracts. Show all posts
Showing posts with label CodeContracts. Show all posts

Thursday, January 08, 2015

.NET Code Contracts are now OSS



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.

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.

Quick Links

Nice to see this open sourced, given the recent silence about it...


Related Past Post XRef:
.Net Code Contracts + XML Comments = (as good as) peanut butter and chocolate?

Sunday, September 06, 2009

.Net Code Contracts + XML Comments = (as good as) peanut butter and chocolate?

Peli's Farm - Pex, Stubs, QuickGraph, MbUnit, Reflector Addins - Code Contracts.Net to Xml Comments!

“The new release of Code Contracts is out and brings a very cool feature: Xml comment generation. This means that you do not have to worry about keeping the comments in sync with the code, the compiler takes care of this.

Contracts to Xml Comments in action

Unless you invest a lot of work in them, Xml comments are most often worthless. …

However, the body of the constructor contains Contracts that state the pre-conditions and post-conditions of the constructor: source and target should not be null, etc… With the new xml comment generation, these contracts will be added to the xml documentation and ultimately will show up in the compiled documentation.

Finally, we run the documentation file through Sandcastle*** to get the final result..



Now that’s pretty cool and very logical. It seems a prefect way to extend and enhance our generated doc’s.

.Net Code Contracts is something I’ve been lightly following on a low priority background thread, waiting for it to bake a little more. Seeing this, I think I’m going to have to increase the priority on that thread. (Yeah it’s a little thing, but little things add up to some pretty big things… ;)