Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

13
  • 5
    That paper is 30 years old. Perhaps some more updated information might be useful? For example, Wikipedia states: "Design by contract does not replace regular testing strategies, such as unit testing, integration testing and system testing. Rather, it complements external testing with internal self-tests that can be activated both for isolated tests and in production code during a test-phase." ... Commented Sep 30, 2021 at 15:57
  • ... "The advantage of internal self-tests is that they can detect errors before they manifest themselves as invalid results observed by the client. This leads to earlier and more specific error detection." Commented Sep 30, 2021 at 15:57
  • If your question is "should I test every contract assertion I write," I'd say the answer is "no". In general, don't write trivial unit tests. Forgetting to put in an assertion is morally equivalent to forgetting to put in a field, and you don't write tests for that. Commented Sep 30, 2021 at 16:09
  • But, @RobertHarvey, if you write an assertion, but you don't have a test for it, what is the purpose of the assertion other than perhaps documentation. I'm failing to see its value. How do you justify that? Commented Sep 30, 2021 at 16:13
  • 1
    Because if your assertion fails, your development environment stops running. Ergo, you've trapped the problem before it gets to production. Assertions are a form of Code Contract; see here. Commented Sep 30, 2021 at 16:16