Search code examples
testingdesign-by-contract

How to make sure contracts in DbC being tested before rollout?


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?


Solution

  • 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.