0

How do you make sure the contracts you defined for your software components using Design by Contract (DbC) are being tested at some point?

Shall I write unit tests for every single contract I define?

One benefit I see in DbC vs. isolated testing of single units is that I'm able to make sure the contract works between real collaborators. But how can I make sure the contracts are being tested before I rollout the software?

1 Answer 1

0

One way is to write a program that simulates users of your application, i.e. a bot. Startup your application with contracts enabled and have the bots exercise the app. You can implement randomized behavior in your bots to have them exercise a larger set of use cases and edge cases. Personally I often extend bots I write to verify performance to enable the sort of testing you're after.

3
  • So basically you are testing your contracts indirectly using any sort of integration testing?
    – bastian
    Commented Feb 6, 2015 at 17:15
  • Sort of. Except that randomized behavior makes it more likely that use cases you haven't explicitly thought about are executed. Commented Feb 6, 2015 at 21:30
  • Also, you should run the tests with code coverage turned on on the server side to make sure that you're not missing any use cases. Commented Feb 6, 2015 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.