3 ms·
Not having any experience with contracts like this, I wonder how this relates to testing. Is this thought to be an addition or an alternative to usual xUnit sty
by ajmurmann 16y ago
Not having any experience with contracts like this, I wonder how this relates to testing. Is this thought to be an addition or an alternative to usual xUnit style and integration tests. Or are these concepts not even related and I am getting it all wrong?
- endlessvoid94 16y agoIt's based on the idea of formal proofs for programs. There is a really good paper about this by dijkstra, but I can't seem to find it now. Basically you defined preconditions and postconditions for each function and it looks like this "contracts" flag will raise an exception if those conditions aren't met. This is probably a better way to test software, but you still need to know how to write the preconditions and postconditions concisely.
- elviejo 16y agoThis contracts refer to the concept of "Design by Contract." http://en.wikipedia.org/wiki/Design_by_contract http://en.wikipedia.org/wiki/Design_by_contract The poster child of design by contract is the Eiffel Programming language. http://www.eiffel.com/developers/design_by_contract.html http://www.eiffel.com/developers/design_by_contract.html IMO Contracts help you te really reduce the number of unit test you need to write. And the tests that you DO write are more intersting in the BDD kind of way. I highly recommend to study design by contract. Is one of those things that will make you a better developer in any language you use. A good book with examples in Java and Eiffel is this: Design by Contract, by Example http://www.amazon.com/Design-Contract-Example-Richard-Mitchell/dp/0201634600 http://www.amazon.com/Design-Contract-Example-Richard-Mitche...
- skybrian 16y agoI haven't used contracts, but I think if you have more assertions in your code then you need fewer assertions in your tests. But you still need to exercise the code with about the same number of tests, or your testing won't find the bugs.