package pfff
Install
Dune Dependency
Authors
Maintainers
Sources
md5=d069f379342be72574b4cdc52f4ed9b4
sha512=68e9971364f5e016bad8f94bb72fd15252f19c7964424992309cdb4a9fc922dbe15d07619f500f4bcbc72f820c93d4da20f0759bb4276cd073a29a179bef9300
doc/commons/OUnit/index.html
Module OUnit
The OUnit library can be used to implement unittests
To uses this library link with ocamlc oUnit.cmo
or ocamlopt oUnit.cmx
Assertions
Assertions are the basic building blocks of unittests.
Signals a failure. This will raise an exception with the specified string.
Signals a failure when bool is false. The string identifies the failure.
Signals a failure when the string is non-empty. The string identifies the 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.
Asserts if the expected exception was raised. When msg is set it can be used to identify the failure
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.
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"
.
Compare Functions
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:
"MyTestCase" >:: (bracket test_set_up test_fun test_tear_down)
Constructing Tests
The type of tests
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 _ -> ())))]))
test_decorate g tst
Apply g
to test function contains in tst
tree.
test_filter paths tst
Filter test based on their path string representation.
Retrieve Information from Tests
val test_case_count : test -> int
Returns the number of available test cases
type path = node list
The path to the test (in reverse order).
val string_of_node : node -> string
Make a string from a node
val string_of_path : path -> string
Make a string from a path. The path will be reversed before it is tranlated into a string
Performing Tests
Events which occur during a test run
val perform_test : (test_event -> 'a) -> test -> test_result list
Perform the test, allows you to build your own test runner
val run_test_tt : ?verbose:bool -> test -> test_result list
A simple text based test runner. It prints out information during the test.
val run_test_tt_main : test -> test_result list
Main 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