I also had a frustrating time getting going with Fmt and Alcotest when learning OCaml. Part of this was just getting familiar with OCaml & its design patterns but a reasonable chunk was due to the Alcotest API and the lack of a corresponding manual. The situation hasn’t changed much since then, so your own experience is not too surprising Hopefully it will improve shortly.
I would recommend that beginners read the Real World OCaml testing chapter and follow the approach described there. Personally I find ppx_expect
and ppx_inline_test
to offer the best out-of-the-box experience for writing non-property-based tests in OCaml today. Alcotest is perhaps less of a magical black box, but it’s less straightforward and more cumbersome to use even after becoming familiar with it. Once I have time to fix the more basic limitations with Alcotest, I plan to propose adding PPX features of that sort.
By the very arbitrary metric of counting Opam packages that depend on them, Alcotest comes out as the most popular:
$ pkgs=(alcotest ounit2 popper ppx_expect ppx_inline_test qcheck)
for pkg in $pkgs; \
do printf "%-15s " $pkg
opam list --depends-on $pkg --with-test --short | wc -l
done
alcotest 402
ounit2 51
popper 2
ppx_expect 104
ppx_inline_test 85
qcheck 45
This is quite a popular topic on this forum so I won’t retread too much of it here. You may be interested in this thread, which I think is the last time it was discussed. As far as non-Base Stdlib alternatives go, you may be looking for Containers. It has the advantage that its individual modules are independent of each other, so individual snippets can be imported into your own projects quite easily. It’s also quite well-documented as these things go.
Personally, I just default to Base / Core whenever I’m not writing for a released Opam package these days. They’re much harder to consume in pieces, but make up for that in internal consistency & an opinionated approach to safety.