Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There's a compromise. Your coworker is actually onto something, but I think he's doing it wrong. I'm not sure that totally random testing is very useful, but it's certainly not invalid.</p> <p>A program (or unit) specification is a hypothesis that there exists some program that meets it. The program itself is then evidence of that hypothesis. What unit testing ought to be is an attempt to provide counter-evidence to refute that the program works according to the spec.</p> <p>Now, you can write the unit tests by hand, but it really is a mechanical task. It can be automated. All you have to do is write the spec, and a machine can generate lots and lots of unit tests that try to break your code.</p> <p>I don't know what language you're using, but see here:</p> <p>Java <a href="http://functionaljava.org/" rel="noreferrer">http://functionaljava.org/</a></p> <p>Scala (or Java) <a href="http://github.com/rickynils/scalacheck" rel="noreferrer">http://github.com/rickynils/scalacheck</a></p> <p>Haskell <a href="http://www.cs.chalmers.se/~rjmh/QuickCheck/" rel="noreferrer">http://www.cs.chalmers.se/~rjmh/QuickCheck/</a></p> <p>.NET: <a href="http://blogs.msdn.com/dsyme/archive/2008/08/09/fscheck-0-2.aspx" rel="noreferrer">http://blogs.msdn.com/dsyme/archive/2008/08/09/fscheck-0-2.aspx</a></p> <p>These tools will take your well-formed spec as input and automatically generate as many unit tests as you want, with automatically generated data. They use "shrinking" strategies (which you can tweak) to find the simplest possible test case to break your code and to make sure it covers the edge cases well.</p> <p>Happy testing!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload