3 ms·
Depending on the language you're using, there might be some tools to help you. For example, MS recently released a library for Design by Contract (aka Contract
by gambler 15y ago
Depending on the language you're using, there might be some tools to help you.
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.
- blackhole 15y agoThat would be fantastic if I didn't write everything in C++
- xentronium 15y agoGenuine question: doesn't such thing as "design by contract" make for the same bloat as checked exceptions in java?
- gambler 15y agoDbC 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.
- gregors 15y agopex link http://research.microsoft.com/en-us/projects/pex/ http://research.microsoft.com/en-us/projects/pex/