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.

4
  • Unit tests do not prove the correctness of anything. Not sure I understand this, unit tests check their own results surely? Or did you mean a behaviour cannot be proved correct since this may encompass multiple layers? Commented Mar 28, 2018 at 17:56
  • 7
    @RobbieDee I guess, he meant that when you test for fac(5) == 120, you have not proven that fac() does indeed return the factorial of its argument. You have only proven that fac() returns the factorial of five when you pass in 5. And even that is not certain, as fac() could conceivably return 42 instead on the first mondays after a total eclipse in Timbuktu... The problem here is, that you cannot prove compliance by checking individual test inputs, you would need to check all possible inputs, and also prove that you have not forgotten any (like reading the system clock). Commented Mar 29, 2018 at 10:08
  • 1
    @RobbieDee Tests (including unit tests) are a poor substitute, often the best available, for the real goal, a machine checked proof. Consider the entire state space of the units under test, including the state space of any components or mocks therein. Unless you have a very restricted state space, tests cannot cover that state space. Complete coverage would be a proof, but this is only available for tiny state spaces, for example, testing a single object containing a single mutable byte or 16 bit integer. Automated proofs are vastly more valuable. Commented Mar 29, 2018 at 15:56
  • 1
    @cmaster You summarized the difference between a test and a proof very well. Thanks! Commented Mar 29, 2018 at 15:57