# Recommended QuickCheck implementation & other unit test tools?

**URL:** <https://discuss.ocaml.org/t/recommended-quickcheck-implementation-other-unit-test-tools/1027>\
**Category:** Learning\
**Created:** [October 28, 2017, 11:39pm UTC](https://discuss.ocaml.org/t/recommended-quickcheck-implementation-other-unit-test-tools/1027 "2017-10-28T23:39:24Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![perry](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/perry/32/518_2.png) [@perry](https://discuss.ocaml.org/u/perry)\
**Post date:** [October 28, 2017, 11:39pm UTC](https://discuss.ocaml.org/t/recommended-quickcheck-implementation-other-unit-test-tools/1027/1 "2017-10-28T23:39:24Z")

</div>

Yet another beginner question.

1. Google seems to show a number of QuickCheck and QuickCheck-like implementations for OCaml. Is there consensus on which one works best? (I’d rather not try all of them in sequence…)

2. Similarly for unit test frameworks?

---

<div class="post-metadata">

**Author:** ![hcarty](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/hcarty/32/1824_2.png) [@hcarty](https://discuss.ocaml.org/u/hcarty)\
**Post date:** [October 29, 2017, 7:37pm UTC](https://discuss.ocaml.org/t/recommended-quickcheck-implementation-other-unit-test-tools/1027/2 "2017-10-29T19:37:33Z")

</div>

I’ve been very happy with [Alcotest](https://github.com/mirage/alcotest/) for unit tests and [qcheck](https://github.com/c-cube/qcheck) for generating data.

---

<div class="post-metadata">

**Author:** ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)\
**Post date:** [October 29, 2017, 7:49pm UTC](https://discuss.ocaml.org/t/recommended-quickcheck-implementation-other-unit-test-tools/1027/3 "2017-10-29T19:49:09Z")

</div>

For unit testing, I’ve been meaning to try out [http://michipili.github.io/broken/](http://michipili.github.io/broken/) --I like how minimalistic it is, feels like it strips out as much boilerplate as possible.

---

<div class="post-metadata">

**Author:** ![theindigamer](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/theindigamer/32/610_2.png) [@theindigamer](https://discuss.ocaml.org/u/theindigamer)\
**Post date:** [October 29, 2017, 7:51pm UTC](https://discuss.ocaml.org/t/recommended-quickcheck-implementation-other-unit-test-tools/1027/4 "2017-10-29T19:51:05Z")

</div>

+1 to the QCheck recommendation, the documentation explains things nicely.

---

<div class="post-metadata">

**Author:** ![rdavison](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/rdavison/32/4321_2.png) [@rdavison](https://discuss.ocaml.org/u/rdavison)\
**Post date:** [October 29, 2017, 11:50pm UTC](https://discuss.ocaml.org/t/recommended-quickcheck-implementation-other-unit-test-tools/1027/5 "2017-10-29T23:50:50Z")

</div>

While we’re on the subject, has anyone had any success integrating ppx\_expect with jbuilder?

---

<div class="post-metadata">

**Author:** ![Drup](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/drup/32/35_2.png) [@Drup](https://discuss.ocaml.org/u/Drup)\
**Post date:** [October 30, 2017, 1:06am UTC](https://discuss.ocaml.org/t/recommended-quickcheck-implementation-other-unit-test-tools/1027/6 "2017-10-30T01:06:49Z")

</div>

> [@rdavison](#):
>
> While we’re on the subject, has anyone had any success integrating ppx\_expect with jbuilder?

> <https://github.com/ocaml/dune/issues/48>
>
> I would like to test a ppx that I build with jbuilder. I tried several approache…s
> \- The oldschool method : 
> \`\`\`
> ocaml -noinit -noprompt -ppx my\_ppx \< test.ml 2\>&1 | tail -n +19 \> test.result
> diff test.expected test.result
> \`\`\`
> Problem: I can't figure out how to talk about \`my\_ppx\`.
> \- The compiler/jsoo method: inline \`expect\_test\` in my project and use it on my test file
> Problem: Still can't figure out how to talk about the \`my\_ppx\` executable, and not sure how to actually run \`expect\_test\` with it.
> \- The "new" method, with \`toplevel\_expect\_test\`
> Problem: Regardless of the fact that the packaging is so badly done that I can't even actually run it. I have no idea how to actually write the build rules for the toplevel that interact with my ppx.
> 
> So, what's the solution ? I would really like to be \*at least\* able to write the rules for the first (old school) method.

---

<div class="post-metadata">

**Author:** ![cfcs](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/cfcs/32/833_2.png) [@cfcs](https://discuss.ocaml.org/u/cfcs)\
**Post date:** [October 30, 2017, 1:40am UTC](https://discuss.ocaml.org/t/recommended-quickcheck-implementation-other-unit-test-tools/1027/7 "2017-10-30T01:40:08Z")

</div>

It may also be worth having a look at the various AFL-based generators like  
@stedolan’s [crowbar](https://github.com/stedolan/crowbar),  
@yomimono’s [ocaml-bun](https://github.com/yomimono/ocaml-bun) , …

I have yet to find a good article about or easy-to-follow example of how to set it up, but I think the technique has potential.  
Maybe someone who has a better grip on this tooling can elaborate a bit.

---

<div class="post-metadata">

**Author:** ![yomimono](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yomimono/32/192_2.png) [@yomimono](https://discuss.ocaml.org/u/yomimono)\
**Post date:** [October 30, 2017, 3:20am UTC](https://discuss.ocaml.org/t/recommended-quickcheck-implementation-other-unit-test-tools/1027/8 "2017-10-30T03:20:41Z")

</div>

ocaml-bun is intended for nice management of afl-fuzz/crowbar workflows, so I’d recommend looking at Crowbar first 🙂

the Crowbar repository itself is lacking in documentation but has some examples from which it’s possible to do a bit of divination around how the workflow goes. I wrote a bit about using it [here](https://somerandomidiot.com/blog/2017/04/26/crowbar-dhcp/), and the tests it refers to are [on github](https://github.com/yomimono/somerandompacket/tree/master/dhcp/src) . Crowbar isn’t yet released and the API is in flux; some breaking changes got merged a few days ago, so if you want to try any existing tests out (including most of those in the Crowbar repository’s examples directory) you’ll want to check out commit [cffd7df0ab1daa9109220c329eba871c0759db98](https://github.com/stedolan/crowbar/commit/cffd7df0ab1daa9109220c329eba871c0759db98) .

I’m interested myself in existing examples of OCaml projects with generative or property-based tests, regardless of the specific framework used.

---

<div class="post-metadata">

**Author:** ![cfcs](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/cfcs/32/833_2.png) [@cfcs](https://discuss.ocaml.org/u/cfcs)\
**Post date:** [October 30, 2017, 3:59am UTC](https://discuss.ocaml.org/t/recommended-quickcheck-implementation-other-unit-test-tools/1027/9 "2017-10-30T03:59:42Z")

</div>

I have used QCheck a little bit, for example:

- Punycode: [a UTF-8 generator](https://github.com/cfcs/ocaml-punycode/blob/master/tests/testPunycode.ml#L48-L69)  
which found this bug [https://github.com/cfcs/ocaml-punycode/issues/1](https://github.com/cfcs/ocaml-punycode/issues/1) that I still haven’t solved.

- Socks:

I think it would be a shame to claim that any of these constitute particularly well-written examples of QCheck usage, but maybe there are parts that can be copy-pasted from.

---

<div class="post-metadata">

**Author:** ![MiloDavis](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/milodavis/32/475_2.png) [@MiloDavis](https://discuss.ocaml.org/u/MiloDavis)\
**Post date:** [October 30, 2017, 8:23am UTC](https://discuss.ocaml.org/t/recommended-quickcheck-implementation-other-unit-test-tools/1027/10 "2017-10-30T08:23:24Z")

</div>

No. I spent a few hours trying, but couldn’t figure it out.

---

<div class="post-metadata">

**Author:** ![dbuenzli](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dbuenzli/32/18_2.png) [@dbuenzli](https://discuss.ocaml.org/u/dbuenzli)\
**Post date:** [October 30, 2017, 9:14am UTC](https://discuss.ocaml.org/t/recommended-quickcheck-implementation-other-unit-test-tools/1027/11 "2017-10-30T09:14:52Z")

</div>

> [@yomimono](#):
>
> I’m interested myself in existing examples of OCaml projects with generative or property-based tests, regardless of the specific framework used.

@yomimono I think [`fpath`](https://github.com/dbuenzli/fpath/tree/master/test) and [`astring`](https://github.com/dbuenzli/astring/tree/master/test)’s test suites already got treatment from @stedolan but you are welcome to torture `Gg`’s [test suite](https://github.com/dbuenzli/gg/tree/master/test) (which uses it’s own property and generative testing framework I never polished to release).

---

<div class="post-metadata">

**Author:** ![BikalGurung](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bikalgurung/32/5105_2.png) [@BikalGurung](https://discuss.ocaml.org/u/BikalGurung)\
**Post date:** [October 30, 2017, 9:44am UTC](https://discuss.ocaml.org/t/recommended-quickcheck-implementation-other-unit-test-tools/1027/12 "2017-10-30T09:44:09Z")

</div>

+1 Another vote for the combo.

Although for QuickCheck, `crowbar` may be of interest. Mirage developers seem to use them.

[http://ocamllabs.io/general/2017/10/24/Bun.html](http://ocamllabs.io/general/2017/10/24/Bun.html)  
[https://github.com/stedolan/crowbar](https://github.com/stedolan/crowbar)  
[https://github.com/yomimono/ocaml-bun](https://github.com/yomimono/ocaml-bun)

EDIT: links.  
B.

---

<div class="post-metadata">

**Author:** ![copy](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/copy/32/480_2.png) [@copy](https://discuss.ocaml.org/u/copy)\
**Post date:** [October 30, 2017, 7:33pm UTC](https://discuss.ocaml.org/t/recommended-quickcheck-implementation-other-unit-test-tools/1027/13 "2017-10-30T19:33:17Z")

</div>

I got it working using the setup described [here](https://gist.github.com/copy/320c5129fcfa85eea8fda98214454aca) (adapted from [this comment](https://github.com/janestreet/ppx_inline_test/issues/8#issuecomment-323529910)).
