module OUnit:sig..end
The OUnit library can be used to implement unittests
To uses this library link with
ocamlc oUnit.cmo
or
ocamlopt oUnit.cmx
Assertions are the basic building blocks of unittests.
val assert_failure : string -> 'aSignals a failure. This will raise an exception with the specified string.
Failure to signal a failureval assert_bool : string -> bool -> unitSignals a failure when bool is false. The string identifies the failure.
Failure to signal a failureval (@?) : string -> bool -> unitShorthand for assert_bool
Failure to signal a failureval assert_string : string -> unitSignals a failure when the string is non-empty. The string identifies the failure.
Failure to signal a failureval assert_equal : ?cmp:('a -> 'a -> bool) ->
?printer:('a -> string) -> ?msg:string -> 'a -> 'a -> unitCompares 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.
Failure descriptionval assert_raises : ?msg:string -> exn -> (unit -> 'a) -> unitAsserts if the expected exception was raised. When msg is set it can be used to identify the failure
Failure descriptionIn 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 -> unitskip 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 -> unitThe associated test is still to be done, for the reason given.
val cmp_float : ?epsilon:float -> float -> float -> boolCompare floats up to a given relative error.
A bracket is a functional implementation of the commonly used setUp and tearDown feature in unittests. It can be used like this:
"MyTestCase" >:: (bracket test_set_up test_fun test_tear_down)
val bracket : (unit -> 'a) -> ('a -> 'b) -> ('a -> 'c) -> unit -> 'ctypetest_fun =unit -> unit
The type of test function
type test =
| |
TestCase of |
| |
TestList of |
| |
TestLabel of |
The type of tests
val (>:) : string -> test -> testCreate a TestLabel for a test
val (>::) : string -> test_fun -> testCreate a TestLabel for a TestCase
val (>:::) : string -> test list -> testCreate a TestLabel for a TestList
Some shorthands which allows easy test construction.
Examples:
"test1" >: TestCase((fun _ -> ())) =>
TestLabel("test2", TestCase((fun _ -> ())))"test2" >:: (fun _ -> ()) =>
TestLabel("test2", TestCase((fun _ -> ())))"test-suite" >::: ["test2" >:: (fun _ -> ());] =>
TestLabel("test-suite", TestSuite([TestLabel("test2", TestCase((fun _ -> ())))]))val test_decorate : (test_fun -> test_fun) -> test -> testtest_decorate g tst Apply g to test function contains in tst tree.
val test_filter : string list -> test -> test optiontest_filter paths tst Filter test based on their path string representation.
val test_case_count : test -> intReturns the number of available test cases
type node =
| |
ListItem of |
| |
Label of |
Types which represent the path of a test
typepath =node list
The path to the test (in reverse order).
val string_of_node : node -> stringMake a string from a node
val string_of_path : path -> stringMake a string from a path. The path will be reversed before it is tranlated into a string
val test_case_paths : test -> path listReturns a list with paths of the test
type test_result =
| |
RSuccess of |
| |
RFailure of |
| |
RError of |
| |
RSkip of |
| |
RTodo of |
The possible results of a test
type test_event =
| |
EStart of |
| |
EEnd of |
| |
EResult of |
Events which occur during a test run
val perform_test : (test_event -> 'a) -> test -> test_result listPerform the test, allows you to build your own test runner
val run_test_tt : ?verbose:bool -> test -> test_result listA simple text based test runner. It prints out information during the test.
val run_test_tt_main : test -> test_result listMain version of the text based test runner. It reads the supplied command line arguments to set the verbose level and limit the number of test to run