11
votes

A number of years ago a Java testing tool called Agitar was popular. It appeared to do something like property based testing.

Nowadays - property based testing based on Haskell's Quickcheck is popular. There are a number of ports to Java including:

My question is: What is the difference between Agitar and Quickcheck property based testing?

2
Does agitar use randomized testing? How are properties formulated there? Please tell us moreNiklas B.
Apparently quickcheck for Java doesn't support shrinking. Also, AFAICT, it doesn't "expand" either, by which I mean it doesn't start by testing the simplest cases and then gradually make the tests more complicated. I don't know if any of the others support shrinking and expanding, but that could be an important feature to check.mhwombat
From the description it sounds like Agitar generates unit tests based on code; Quickcheck doesn't generate tests, it tests properties with randomly generated inputs.Cubic
Thanks @mhwombat please expand that into an answer and I'll mark it as correct.hawkeye
Thanks @Cubic - please expand that into an answer and I'll mark it as correct.hawkeye

2 Answers

12
votes

To me, the key features of Haskell QuickCheck are:

  1. It generates random data for testing

  2. If a test fails, it repeatedly "shrinks" the data (e.g., changing numbers to zero, reducing the size of a list) until it finds the simplest test case that still fails. This is very useful, because when you see the simplest test case, you often know exactly where the bug is and how to fix it.

  3. It starts testing with simple data, and gradually moves on to more complex data. This is useful because it means that tests fail more quickly. Also, it ensures that edge cases (e.g., empty lists, zeroes) are properly tested.

Quickcheck for Java supports (1), but not (2) or (3). I don't know what features are supported by Agitar, but it would be useful to check.

Additionally, you might look into ScalaCheck. Since Scala is interoperable with Java, you could use it to test your Java code. I haven't used it, so I don't know which features it has, but I suspect it has more features than Java Quickcheck.

5
votes

Its worth noting that as of version 0.6, junit-quickcheck now supports shrinking:

http://pholser.github.io/junit-quickcheck/site/0.6-alpha-3-SNAPSHOT/usage/shrinking.html

quickcheck doesn't look to have had any new releases since 2011:

https://bitbucket.org/blob79/quickcheck