Unit test building blocks
Assertions are the basic building blocks of unittests.
Signals a failure. This will raise an exception with the specified string.
Failure signal a failure
Signals a failure when bool is false. The string identifies the failure.
Failure signal a failure
Shorthand for assert_bool
Failure to signal a failure
Signals a failure when the string is non-empty. The string identifies the failure.
Failure signal a failure
assert_command prg args Run the command provided.
char Stream.t as input of the process
assert_equal to check it
stderr to stdout
assert_equal expected real Compares two values, when they are not equal a
failure is signaled.
=
diff fmt exp real where fmt is the formatter to use
Failure signal a failure
Asserts if the expected exception was raised.
Failure description
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".
The associated test is still to be done, for the reason given.
Compare floats up to a given relative error.
epsilon values are equal
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.
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.
Filename.open_temp_file
Filename.open_temp_file
Filename.open_temp_file
The type of test function
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 _ -> ())))]))Make a string from a path. The path will be reversed before it is tranlated into a string
Perform the test, allows you to build your own test runner
A simple text based test runner.
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.