Legend:
Library
Module
Module type
Parameter
Class
Class type
The OUnit library can be used to implement unittests
To uses this library link with ocamlc oUnit.cmo or ocamlopt oUnit.cmx
author Maas-Maarten Zeeman
Assertions
Assertions are the basic building blocks of unittests.
val assert_failure : string ->'a
Signals a failure. This will raise an exception with the specified string.
raisesFailure
to signal a failure
val assert_bool : msg:string ->bool -> unit
Signals a failure when bool is false. The string identifies the failure.
raisesFailure
to signal a failure
val (@?) : string ->bool -> unit
Shorthand for assert_bool
raisesFailure
to signal a failure
val assert_string : string -> unit
Signals a failure when the string is non-empty. The string identifies the failure.
raisesFailure
to signal a failure
val assert_equal :
?cmp:('a->'a-> bool)->?printer:('a-> string)->?msg:string ->'a->'a->
unit
Compares two values, when they are not equal a failure is signaled. The cmp parameter can be used to pass a different compare function. This parameter defaults to ( = ). The optional printer can be used to convert the value to string, so a nice error message can be formatted. When msg is also set it can be used to identify the failure.
raisesFailure
description
val assert_raises : ?msg:string ->exn ->(unit ->'a)-> unit
Asserts if the expected exception was raised. When msg is set it can be used to identify the failure
raisesFailure
description
Skipping tests
In certain condition test can be written but there is no point running it, because they are not significant (missing OS features for example). In this case this is not a failure nor a success. Following function allow you to escape test, just as assertion but without the same error status.
A test skipped is counted as success. A test todo is counted as failure.
val skip_if : bool ->string -> unit
skip cond msg If cond is true, skip the test for the reason explain in msg. * For example skip_if (Sys.os_type = "Win32") "Test a doesn't run on windows".
val todo : string -> unit
The associated test is still to be done, for the reason given.
Compare Functions
val cmp_float : ?epsilon:float ->float ->float -> bool
Compare floats up to a given relative error.
Bracket
A bracket is a functional implementation of the commonly used setUp and tearDown feature in unittests. It can be used like this: