Tool/Technique for Automatic Unit Test Generation based on Method Pre-/Post-Conditions

596 Views Asked by At

I wonder if there is any tool that automatically generates unit tests based on a method's pre- and post-conditions (and class invariant).

To be precise, suppose we are given pre- and post-conditions (and probably class invariant) for a method and we want to generate unit tests based on that information. I am looking for a practical tool for this purpose.

I know Korat and TestWizard. Could you please name a few more techniques/tools?

PS: Programming language, or the language using which we specify the method contracts, is not that important. I just want to know about the techniques.

Thank you.

2

There are 2 best solutions below

1
mernst On

Randoop does that. Its manual tells you how to specify pre- and post-conditions.

In a comment you made a distinction between "generating" and "guiding"; I'm not sure exactly what you mean by that, but you might view Randoop as using the specifications for guidance.

2
Alexander Kogtenkov On

One of research activities in this area was carried out in 2005-2011 in ETH to make a "Contract-based random testing tool", aka AutoTest. It was developed for Eiffel where preconditions, postconditions and class invariants are part of the language. The tool uses them as a specification to generate tests automatically. The tool was integrated with EiffelStudio development environment where it employs contracts for 3 kinds of tests:

  • manual - a good "old-school" approach by writing tests by developers;
  • extracted - as soon as there is a contract violation, the tool can generate the corresponding test case;
  • generated - the tool synthesizes new tests automatically by making sure preconditions and class invariants are satisfied on entry to a routine and checking that there is no failure on return, in particular, that there is no postcondition or class invariant violation.