Use OUnit module in OCaml - Unbound module OUnit error

ocaml, opam, ounit, unit-testing

Solution

You should use for example:

ocamlfind ocamlc -package oUnit -linkpkg -o unit unit.ml

`ocamlfind` is an utility that encapsulates lookup of installed libraries. You can also avoid composing compiler-invocation yourself and use a build tool.

Problem

I'm trying to use OUnit with OCaml. The unit code source (unit.ml) is as follows: ``` open OUnit let empty_list = [] let list_a = [1;2;3] let test_list_length _ = assert_equal 1 (List.length empty_list); assert_equal 3 (List.length list_a) (* etc, etc *) let test_list_append _ = let list_b = List.append empty_list [1;2;3] in assert_equal list_b list_a let suite = "OUnit Example" >::: ["test_list_length" >:: test_list_length; "test_list_append" >:: test_list_append] let _ = run_test_tt_main suite ``` With `ocamlc unit.ml`, I got an error message `Error: Unbound module OUnit`. Why is this? How can I use the OUnit in OCaml. I installed OUnit with `opam`.

Original source