module OUnit:sig
..end
Assertions are the basic building blocks of unittests.
val assert_failure : string -> 'a
Failure
signal a failureval assert_bool : string -> bool -> unit
Failure
signal a failureval (@?) : string -> bool -> unit
Failure
to signal a failureval assert_string : string -> unit
Failure
signal a failureval 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 -> unit
assert_command prg args
Run the command provided.exit_code
: expected exit codesinput
: provide this char Stream.t
as input of the processfoutput
: run this function on output, it can contains an
assert_equal
to check ituse_stderr
: redirect stderr
to stdout
env
: Unix environmentverbose
: if failed, dump stdout/stderr of the process to stderrval assert_equal : ?cmp:('a -> 'a -> bool) ->
?printer:('a -> string) ->
?pp_diff:(Format.formatter -> 'a * 'a -> unit) ->
?msg:string -> 'a -> 'a -> unit
assert_equal expected real
Compares two values, when they are not equal a
failure is signaled.Failure
signal a failurecmp
: customize function to compare, default is =
printer
: value printer, don't print value otherwisepp_diff
: if not equal, ask a custom display of the difference
using diff fmt exp real
where fmt
is the formatter to usemsg
: custom message to identify the failureval assert_raises : ?msg:string -> exn -> (unit -> 'a) -> unit
Failure
descriptionmsg
: identify the failureIn 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.
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
val cmp_float : ?epsilon:float -> float -> float -> bool
epsilon
: if the difference is smaller epsilon
values are equalA 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 -> unit) -> ('a -> unit) -> unit -> unit
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:Pervasives.open_flag list ->
(string * Pervasives.out_channel -> unit) -> unit -> unit
bracket_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.prefix
: see Filename.open_temp_file
suffix
: see Filename.open_temp_file
mode
: see Filename.open_temp_file
typetest_fun =
unit -> unit
type
test =
| |
TestCase of |
| |
TestList of |
| |
TestLabel of |
val (>:) : string -> test -> test
val (>::) : string -> test_fun -> test
val (>:::) : string -> test list -> test
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 -> test
test_decorate g tst
Apply g
to test function contains in tst
tree.val test_filter : ?skip:bool -> string list -> test -> test option
test_filter paths tst
Filter test based on their path string
representation.skip
: if set, just use skip_if
for the matching tests.val test_case_count : test -> int
type
node =
| |
ListItem of |
| |
Label of |
typepath =
node list
val string_of_node : node -> string
val string_of_path : path -> string
val test_case_paths : test -> path list
type
test_result =
| |
RSuccess of |
| |
RFailure of |
| |
RError of |
| |
RSkip of |
| |
RTodo of |
type
test_event =
| |
EStart of |
(* | A test start. | *) |
| |
EEnd of |
(* | A test end. | *) |
| |
EResult of |
(* | Result of a test. | *) |
typetest_results =
test_result list
val perform_test : (test_event -> unit) -> test -> test_results
val run_test_tt : ?verbose:bool -> test -> test_results
verbose
: print verbose messageval run_test_tt_main : ?arg_specs:(Arg.key * Arg.spec * Arg.doc) list ->
?set_verbose:(bool -> unit) -> test -> test_results
arg_specs
: add extra command line argumentsset_verbose
: call a function to set verbosityval ounit2_of_ounit1 : test -> OUnit2.test