Skip to main content
This revision made December 31, 2012 13:01, by blob79

Project moved to bitbucket!

The project is now developed on bitbucket! Please update for links.

Quickcheck

QuickCheck is an implementation of the Haskell QuickCheck specification based test tool.

The goal of QuickCheck is to replace scenario-based testing with specification-based testing. A QuickCheck-based test tries to cover the laws of a domain whereas classical scenario-based testing can only test the validity for heuristically (manually) picked values. In the absence of tools that could confirm the compliance to a specification (like compilers can confirm the validity of source code for a type system) QuickCheck tests the specification with generated values.

Basically QuickCheck is about generators of data. The QuickCheck runner method is just a fancy for loop implementation. QuickCheck can help in scenarios where whole classes of test cases have to be tested and it is not feasible to write tests for all distinct test scenarios.

Generators supported for

  • types (primitive: int, byte, long, String, char, null, boolean; collections: arrays, lists; POJOs)
  • value ranges (integer, chars)
  • lists, sets and array
  • distinct values (uniqueValues, ensureValues, fixedValues, enumValues, clonedValues, excludeValues)
  • distributions
  • generator strategies (composition of generator values (oneOf, frequency, list, array, nullsAnd), transformation, mutation)
  • value frequencies (frequency, oneOf)
  • determinism (random, deterministic )

Documentation

API

The Quickcheck Javadoc is available here.

Introduction

Other

Example

The following example test that a sorted list implementation is actual sorted. The values inserted into the list are arbitrary integer values.

public class SortedListTest {

   @Test public void sortedListCreation() {
      for (List<Integer> any : someLists(integers())) {
         SortedList sortedList = new SortedList(any);
         List<Integer> expected = sort(any);
         assertEquals(expected, sortedList.toList());
      }
   }
   
  private List<Integer> sort(List<Integer> any) {
      ArrayList<Integer> sorted = new ArrayList<Integer>(any);
      Collections.sort(sorted);
      return sorted;
   }
}
More examples can be found in the here or in the assembly.

Releases

QuickCheck 0.6 March 19, 2011 Release notes

QuickCheck 0.5.1 February 17, 2011

QuickCheck 0.5 January 2, 2010 Release notes

QuickCheck 0.4 June 3, 2009

QuickCheck 0.3 March 23, 2008

QuickCheck 0.2 July 23, 2007

QuickCheck 0.1 July 7, 2007

Help

Project QuickCheck needs help in the following areas:

  • Todos
  • Sample code.
    • The test code in Robert C. Martin's Clean Code offers plenty of opportunities to show Quickheck's strengths.
    • One possibility is to port the code from Alberto Savoia's Beautiful code chapter Beautiful Tests and make it beautiful with Quickcheck
Difference compared to previous revision
<span>=<span style="text-decoration:underline;color:green">Project</span> <span style="text-decoration:underline;color:green">moved to bitbucket!= The project is now developed on [http://bitbucket.org/blob79/quickcheck bitbucket]! Please update for links. = </span>= Quickcheck = [http://java.net/projects/quickcheck QuickCheck] is an implementation of the [http://www.haskell.org/haskellwiki/Introduction_to_QuickCheck Haskell QuickCheck] specification based test tool. ... * [http://java.net/projects/quickcheck/sources/repository/content/todo.txt Todos] * Sample code. ** The test code in Robert C. Martin's Clean Code offers plenty of opportunities to show Quickheck's strengths. ** One possibility is to port the code from Alberto Savoia's Beautiful code chapter Beautiful Tests and make it beautiful with Quickcheck<span style="text-decoration:line-through;color:red"> </span> <span>
 
 
Close
loading
Please Confirm
Close