module Utest:sig
..end
Utest
supplies a simple framework for performing unit-tests in an
Extreme Programming style. It has been influenced by Greg (Gnu
REGression testing) and Maas-Maarten Zeeman's oUnit.
type
expected_test_outcome =
| |
ExpectPass |
(* | We expect to pass the test. | *) |
| |
ExpectFail |
(* | We expect to fail the test. | *) |
| |
ExpectException of |
(* | We expect that the given exception will be raised. | *) |
type
test_outcome =
| |
Pass |
(* | We expected passing and we passed. | *) |
| |
Fail |
(* | We expected passing but we failed. | *) |
| |
UPass |
(* | We expected failing but we did succeed. | *) |
| |
XFail |
(* | We expected failed and we failed. | *) |
| |
Unresolved of |
(* | An unexpected exception occurred. The argument is the exception's text, | *) |
type
test =
| |
TestCase of |
type
test_results = {
|
total : |
(* | Total number of test cases attempted | *) |
|
passed : |
(* | Number of passed tests | *) |
|
failed : |
(* | Number of failed tests | *) |
|
upassed : |
(* | Number of unexpectedly passed tests | *) |
|
xfailed : |
(* | Number of expectedly failed tests | *) |
|
unresolved : |
(* | Number of unresolved tests | *) |
val testcase : string -> expected_test_outcome -> (unit -> bool) -> test
testcase a_test_title an_expected_outcome a_test_function
Create a single testcase of a_test_function
with a_test_title
and an_expected_outcome
.
Note that this is a "low-level" function and the two convenience
functions Utest.expect_pass
and Utest.expect_fail
allow for
a terser definition of a test.
val expect_pass : string -> (unit -> bool) -> test
val expect_fail : string -> (unit -> bool) -> test
val expect_exception : string -> exn -> (unit -> bool) -> test
exception InconsistentFixture
val eval_with_imperative_fixture : (unit -> 'a) -> ('a -> test) -> ('a -> unit) -> unit -> test
eval_with_imperative_fixture a_setup_function a_test_function a_teardown_function
Evaluate a_test_function
by passing the result of
a_setup_function
. After a_test_function
completes, pass the
result of a_setup_function
to a_teardown_function
.
This is for example useful of a_test_function
need the handles
of some open files. In this case a_setup_function
would open
the files and pass the handle (the fixture).
a_teardown_function
closes the files after a_test_function
completes.
val eval_with_functional_fixture : (unit -> 'a) -> ('a -> test) -> unit -> test
type
verbosity =
| |
PrintNothing |
(* | Do not print anything | *) |
| |
PrintFailedTests |
(* | Only print failed tests | *) |
| |
PrintTestTotals |
(* | Show test totals | *) |
| |
PrintAllTests |
(* | Display each single test | *) |
val run_tests : verbosity -> (unit -> test) list -> test_results
run_tests ~verbose a_list_of_tests
Run all tests in a_list_of_tests
. The verbose
flag controls
whether the function prints each test result or just the totals.