Must code contracts and pex be applied in a tdd fashion? Is it possible to apply these testing techniques to 3rd party or legacy code?
For a background, I invite people to watch http://channel9.msdn.com/posts/Peli/The-Synergy-of-Code-Contracts-and-Pex/ to get an idea on how Pex/Contracts may work together.
My answer would be no. Pex and Contracts can both be applied to 3rd party/legacy code, but they really shine when used together:
- Pex can explore any regardless whether it's 3rd party or legacy. You can use Pex to generate a regression suite for your legacy code (or use the highly experimental 'fix it' feature to infer missing preconditions).
- Code Contracts can be defined 'out-of-band', i.e. in separate assemblies. So potentially, you could annotate 3rd party code with Contracts. This point is not so obvious though: how much effort are you willing to invest in 3rd party/legacy code?