Has anyone experimented with Code Contracts for .NET

Bulldog13

Golden Member
Jul 18, 2002
1,655
1
81
Title pretty much explains it all. Does anyone have an opinion on Code Contracts (http://msdn.microsoft.com/en-us/devlabs/dd491992) ?

I am doing some greenfield development unit tests and find myself doing alot of null checking and was wondering if this would be an easier way to go about it?

Before I dedicated the time to learning it though, I was wondering if anyone had positive reviews on them.

Thanks
 

Krioni

Golden Member
Feb 4, 2000
1,371
0
71
I've only read the stuff about them.. they seem pretty interesting. Hoping you get some responses to this :)
 

BrightCandle

Diamond Member
Mar 15, 2007
4,762
0
76
Contracts are a brilliant way for some types of problems. Algorithmic tests that are numerical or produce particular simple results from input->output (pure functional) are simple enough to produce invariants for in general its more natural to do it this way.

Less algorithmic parts such as code with side effects or where your checking message passing from object to object become more problematic with invariant tests and you end up relying on normal case base unit tests.

A mix of the two approaches is best depending on what your testing.
 

BrightCandle

Diamond Member
Mar 15, 2007
4,762
0
76
Contracts are a brilliant way for some types of problems. Algorithmic tests that are numerical or produce particular simple results from input->output (pure functional) are simple enough to produce invariants for in general its more natural to do it this way.

Less algorithmic parts such as code with side effects or where your checking message passing from object to object become more problematic with invariant tests and you end up relying on normal case base unit tests.

A mix of the two approaches is best depending on what your testing.