package ounit
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=c04a53bfab11789a3d333d2a4fb16cdfaa71e2f8fb34edfc6a93b3e85f1fcd68
md5=dbda9f8a5afe33461f638c2cc0a9e8f6
doc/oUnit/OUnit/index.html
Module OUnit
Unit test building blocks
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_command :
?exit_code:Unix.process_status ->
?sinput:char Stream.t ->
?foutput:(char Stream.t -> unit) ->
?use_stderr:bool ->
?env:string array ->
?verbose:bool ->
string ->
string list ->
unitassert_command prg args Run the command provided.
val assert_equal :
?cmp:('a -> 'a -> bool) ->
?printer:('a -> string) ->
?pp_diff:(Format.formatter -> ('a * 'a) -> unit) ->
?msg:string ->
'a ->
'a ->
unitassert_equal expected real Compares two values, when they are not equal a failure is signaled.
Asserts if the expected exception was raised.
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 functions 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)
bracket set_up test tear_down The set_up function runs first, then the test function runs and at the end tear_down runs. The tear_down function runs even if the test failed and help to clean the environment.
val bracket_tmpfile :
?prefix:string ->
?suffix:string ->
?mode:open_flag list ->
((string * out_channel) -> unit) ->
unit ->
unitbracket_tmpfile test The test function takes a temporary filename and matching output channel as arguments. The temporary file is created before the test and removed after the test.
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 -> intReturns the number of available test cases
type path = node listThe 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
Performing Tests
type test_event = | EStart of path(*A test start.
*)| EEnd of path(*A test end.
*)| EResult of test_result(*Result of a test.
*)
Events which occur during a test run.
type test_results = test_result listResults of a test run.
val perform_test : (test_event -> unit) -> test -> test_resultsPerform the test, allows you to build your own test runner
val run_test_tt : ?verbose:bool -> test -> test_resultsA simple text based test runner.
val run_test_tt_main :
?arg_specs:(Arg.key * Arg.spec * Arg.doc) list ->
?set_verbose:(bool -> unit) ->
test ->
test_resultsMain 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.
val ounit2_of_ounit1 : test -> OUnit2.test