Debian Codegraph @

website/content/2016-04-16-quickcheck-in-every-language.md

raw
1 ---
2 tags: alternatives, technical
3 date: 2016-04-16 15:00
4 title: QuickCheck in Every Language
5 author: drmaciver
6 ---
7
8 <p>
9 There are a lot of ports of <a href="https://en.wikipedia.org/wiki/QuickCheck">QuickCheck</a>,
10 the original property based testing library, to a variety of different languages.
11 </p>
12
13 <p>
14 Some of them are good. Some of them are <em>very</em> good. Some of them are OK. Many are not.
15 </p>
16
17 <p>
18 I thought it would be worth keeping track of which are which, so I've put together a list.
19 </p>
20
21 <!--more-->
22
23 <p>In order to make it onto this list, an implementation has to meet the following criteria:</p>
24
25 <ol>
26 <li>Must support random generation of data to a test function. e.g. testing systems based on
27 <a href="https://hackage.haskell.org/package/smallcheck">smallcheck</a> while interesting and related
28 don't fit on this list.
29 </li>
30 <li>It must be fairly straightforward to generate your own custom types.</li>
31 <li>It must support shrinking of falsifying examples.</li>
32 <li>It must be under active development, in the sense that bugs in it will get fixed.</li>
33 <li>Must be under an OSI approved license.</li>
34 </ol>
35 <p>
36 In this I've tried to collect a list of what I think the best ones are for any given language.
37 I haven't used all of these, but I've used some and read and talked to people about the others.
38 </p>
39
40 <h2>Uncontested Winners by Language</h2>
41
42 <p>For many languages there is a clear winner that you should just use. Here are the ones I've
43 found and what I think of them.</p>
44
45
46 <table class="table">
47
48 <thead>
49 <tr>
50 <th>Language</th>
51 <th>Library</th>
52 <th>Our rating</th>
53 </tr>
54 </thead>
55 <tbody>
56 <tr>
57 <td>C</td>
58 <td><a href="https://github.com/silentbicycle/theft">theft</a></td>
59 <td>Good but does not come with a library of data generators.</td>
60 </tr>
61 <tr>
62 <td>C++</td>
63 <td><a href="https://github.com/grogers0/CppQuickCheck">CppQuickCheck</a></td>
64 <td>Unsure</td>
65 </tr>
66 <tr>
67 <td>Clojure</td>
68 <td><a href="https://github.com/clojure/test.check">test.check</a></td>
69 <td>Very good</td>
70 </tr>
71 <tr>
72 <td>Coq</td>
73 <td><a href=https://github.com/QuickChick/QuickChick>QuickChick</a></td>
74 <td>Unsure</td>
75 </tr>
76 <tr>
77 <td>F#</td>
78 <td><a href="https://github.com/fscheck/FsCheck">FsCheck</a></td>
79 <td>Very Good</td>
80 </tr>
81 <tr>
82 <td>Go</td>
83 <td><a href="https://github.com/leanovate/gopter">gopter</a></td>
84 <td>Unsure but looks promising.</td>
85 </tr>
86 <tr>
87 <td>Haskell</td>
88 <td><a href="https://hackage.haskell.org/package/hedgehog">Hedgehog</a></td>
89 <td>Comparatively new, but looks solid. See below.</td>
90 </tr>
91 <tr>
92 <td>Java</td>
93 <td><a href="https://github.com/NCR-CoDE/QuickTheories">QuickTheories</a></td>
94 <td>Unsure. Extremely new but looks promising.</td>
95 </tr>
96 <tr>
97 <td>JavaScript</td>
98 <td><a href="https://github.com/jsverify/jsverify">jsverify</a></td>
99 <td>Good</td>
100 </tr>
101 <tr>
102 <td>PHP</td>
103 <td><a href="https://github.com/giorgiosironi/eris">Eris</a></td>
104 <td>Unsure. Looks promising.</td>
105 </tr>
106 <tr>
107 <td>Python</td>
108 <td><a href="http://hypothesis.works">Hypothesis</a></td>
109 <td>I may be a bit biased on this one, but it's also unambiguously true.</td>
110 </tr>
111 <tr>
112 <td>Ruby</td>
113 <td><a href="https://github.com/abargnesi/rantly">Rantly</a></td>
114 <td>Unsure. We're not convinced, but the alternatives are definitely worse.</td>
115 </tr>
116 <tr>
117 <td>Rust</td>
118 <td><a href="https://github.com/BurntSushi/quickcheck">Quickcheck</a></td>
119 <td>Unsure, but probably very good based on initial appearance and usage level.</td>
120 </tr>
121 <tr>
122 <td>Scala</td>
123 <td><a href="https://www.scalacheck.org/">ScalaCheck</a></td>
124 <td>Very Good</td>
125 </tr>
126 <tr>
127 <td>Swift</td>
128 <td><a href="https://github.com/typelift/SwiftCheck">Swiftcheck</a></td>
129 <td>Unsure</td>
130 </tr>
131 </tbody>
132 </table>
133
134 <p>Where when I've said "Unsure" I really just mean that I think it looks good but
135 I haven't put in the depth of in time to be sure, not that I have doubts.</p>
136
137 <h2>Special case: Haskell</h2>
138
139 <p>
140 <a href="https://hackage.haskell.org/package/QuickCheck">The original QuickCheck</a>
141 was of course written in Haskell, so it may seem odd that it's not the property based testing
142 library I recommend for Haskell!
143 </p>
144
145 <p>
146 The reason is that I feel that the design of classic QuickCheck is fundamentally limiting,
147 and that Hedgehog takes it in the direction that the rest of the property-based testing
148 world is moving (and where most of the implementations for dynamic languages, Hypothesis
149 included, already are). In particular its approach starts from generators rather than
150 type classes, and it has <a href="../integrated-shrinking %}">integrated shrinking</a>,
151 and a fairly comprehensive library of generators.
152 </p>
153
154 <h2>Special case: Erlang</h2>
155
156 <p>
157 Erlang is a special case because they have <a href="http://www.quviq.com/">QuviQ's QuickCheck</a>.
158 Their QuickCheck implementation is by all accounts <em>extremely</em> good, but it is also proprietary
159 and fairly expensive. Nevertheless, if you find yourselves in the right language, circumstance and
160 financial situation to use it, I would strongly recommend doing so.
161 </p>
162
163 <p>
164 In particular, QuviQ's QuickCheck is really the only implementation in this article I think is
165 simply better than Hypothesis. Hypothesis is significantly more user friendly, especially if the
166 users in question are less than familiar with Erlang, but there are things QuviQ can do that
167 Hypothesis can't, and the data generation has had a great deal more engineering effort put into it.
168 </p>
169
170 <p>
171 If you're using Erlang but <em>not</em> able to pay for QuickCheck, apparently the one to use is
172 <a href="https://github.com/manopapad/proper">PropEr</a>. If you're also unable to use GPLed software
173 there's <a href=https://github.com/krestenkrab/triq>triq</a>. I know very little about either.
174 </p>
175
176 <h2>Special case: OCaml</h2>
177
178 <p>
179 OCaml seems to be suffering from a problem of being close enough to Haskell that people try to do a
180 straight port of Quickcheck but far enough from Haskell that this doesn't work. The result is that
181 there is <a href="https://github.com/alanfalloon/ocaml-quickcheck">a "mechanical port" of Quickcheck
182 which is completely abandoned</a> and <a href="https://github.com/camlunity/ocaml-quickcheck">a fork
183 of it that uses more idiomatic OCaml</a>. I'm insufficiently familiar with OCaml or its community
184 to know if either is used or whether there is another one that is.
185 </p>
186
187 <h2>What does this have to do with Hypothesis?</h2>
188
189 <p>
190 In some sense these are all "competitors" to Hypothesis, but we're perfectly happy not to compete.
191 </p>
192
193 <p>
194 In the case of Erlang, I wouldn't even try. In the case of Scala, F#, or Clojure, I might at some
195 point work with them to try to bring the best parts of Hypothesis to their existing implementation,
196 but I don't consider them a priority - they're well served by what they have right now, and there
197 are many languages that are not.
198 </p>
199
200 <p>
201 For the rest though? I'm glad they exist! I care about testing and about high quality software,
202 and they're doing their part to make it possible.
203 </p>
204
205 <p>
206 But I feel they're being badly served by their underlying model, and that they feel quite unnatural
207 to use in the context of a more conventional test setting. I think Hypothesis is the way forward,
208 and I'll be doing my best <a href="/services/#ports-of-hypothesis-to-new-languages">to make it
209 possible for everyone to use it in their language of choice</a>.
210 </p>