X-Git-Url: http://nitlanguage.org diff --git a/share/man/nitunit.md b/share/man/nitunit.md index 4e4ea82..e80e80e 100644 --- a/share/man/nitunit.md +++ b/share/man/nitunit.md @@ -169,6 +169,34 @@ class TestFoo end ~~~~ +## Black Box Testing + +Sometimes, it is easier to validate a `TestCase` by comparing its output with a text file containing the expected result. + +For each TestCase `test_bar` of a TestSuite `test_mod.nit`, if the corresponding file `test_mod.sav/test_bar.res` exists, then the output of the test is compared with the file. + +The `diff(1)` command is used to perform the comparison. +The test is failed if non-zero is returned by `diff`. + +~~~ +module test_mod is test_suite +class TestFoo + fun test_bar do + print "Hello!" + end +end +~~~ + +Where `test_mod.sav/test_bar.res` contains + +~~~raw +Hello! +~~~ + +If no corresponding `.res` file exists, then the output of the TestCase is ignored. + +## Configuring TestSuites + `TestSuites` also provide methods to configure the test run: `before_test` and `after_test`: methods called before/after each test case. @@ -284,6 +312,29 @@ Only display the skeleton, do not write any file. Indicate the specific Nit compiler executable to use. See `--nitc`. +### `NIT_TESTING` + +The environment variable `NIT_TESTING` is set to `true` during the execution of program tests. +Some libraries of programs can use it to produce specific reproducible results; or just to exit their executions. + +Unit-tests may unset this environment variable to retrieve the original behavior of such piece of software. + +### `SRAND` + +In order to maximize reproducibility, `SRAND` is set to 0. +This make the pseudo-random generator no random at all. +See `Sys::srand` for details. + +To retrieve the randomness, unit-tests may unset this environment variable then call `srand`. + +### `NIT_TESTING_ID` + +Parallel executions can cause some race collisions on named resources (e.g. DB table names). +To solve this issue, `NIT_TESTING_ID` is initialized with a distinct integer identifier that can be used to give unique names to resources. + +Note: `rand` is not a recommended way to get a distinct identifier because its randomness is disabled by default. See `SRAND`. + + # SEE ALSO The Nit language documentation and the source code of its tools and libraries may be downloaded from