package ounit
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=c04a53bfab11789a3d333d2a4fb16cdfaa71e2f8fb34edfc6a93b3e85f1fcd68
md5=dbda9f8a5afe33461f638c2cc0a9e8f6
doc/oUnit/OUnit2/index.html
Module OUnit2
Unit test building blocks (v2).
Types
type test_ctxt = OUnitTest.ctxtContext of a test.
type test_fun = test_ctxt -> unitThe type of test function.
type test = OUnitTest.testThe type of test.
type test_length = OUnitTest.test_lengthThe expected length of the test.
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 ->
?backtrace:bool ->
?chdir:string ->
?env:string array ->
ctxt:test_ctxt ->
string ->
string list ->
unitassert_command prg args Run the command provided.
val assert_equal :
?ctxt:test_ctxt ->
?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 registered object with setUp and tearDown in unit tests. Data generated during the setUp will be automatically tearDown when the test ends.
bracket set_up tear_down test_ctxt set up an object and register it to be tore down in test_ctxt.
val bracket_tmpfile :
?prefix:string ->
?suffix:string ->
?mode:open_flag list ->
test_ctxt ->
string * out_channelbracket_tmpfile test_ctxt Create a temporary filename and matching output channel. The temporary file is removed after the test.
val bracket_tmpdir : ?prefix:string -> ?suffix:string -> test_ctxt -> stringbracket_tmpdir test_ctxt Create a temporary dirname. The temporary directory is removed after the test.
with_bracket_chdir test_ctxt dn f change directory to dn during execution of function f. In order to Sys.chdir, we need to take a lock to avoid other tests trying to do change the current directory at the same time. So this bracket is not directly accessible in order to use it only on shorter piece of code.
Constructing Tests
val test_case : ?length:test_length -> test_fun -> testGeneric function to create a test case.
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 _ -> ())))]))
Performing Tests
val logf : test_ctxt -> log_severity -> ('a, unit, string, unit) format4 -> 'aLog into OUnit logging system.
val in_testdata_dir : test_ctxt -> string list -> stringBuild a filename for a file that should be located in the test data dir.
The test data dir, can be defined on the command line (preferably absolute) The default option is to locate it in topsrcdir/test/data.
non_fatal ctxt f Run f but if an exception is raised or an assert fails, don't stop, just register the result. The global test running result will mix in the non fatal result to determine the success or failure of the test.
module Conf : sig ... endDefine command line options, environment variables and file configuration.
val run_test_tt_main : ?exit:(int -> unit) -> test -> unitMain 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.