That would be fantastic if I didn't write everything in C++
Re:When TDD Fails
by xentronium on Saturday October 01, 2011 @10:21PM
(#3061816)
Genuine question: doesn't such thing as "design by contract" make for the same bloat as checked exceptions in java?
DbC doesn't need to be dealt with at every level of the call chain if that's what you mean.
It may seem a bit verbose, but it usually expresses logic that would be in your program or in your tests anyway. Difference is, you will be doing it in a pretty terse and declarative manner. IMO, DbC is one of the coolest features of .NET 4.0.
For example, MS recently released a library for Design by Contract (aka Contract Programming) in .NET 4.0. It allows you to specify constraints on your methods, such as things you expect to be true before the method is called, after, and between all method calls in a class. The library is capable of static verification, but it's partly an experimental feature and you need to pay for expensive version of VS. (Runtime checking is available for free.)
But, here is the cool part: MS also released an automatic test generator called PEX. It can do exactly what you've described - go into your code and automatically find edge cases, and generate tests that cover each of them. And it's free.
So, you can write contracts, run PEX, and if something goes wrong, you will see which inputs generated exceptions.
D also has DbC functionality. I don't think it runs any static verification on it yet, but you can use it to detect abnormalities during functional testing.