![]() |
![]()
| ![]() |
![]()
NAME
DESCRIPTIONA test case is a piece of code that stress-tests a specific feature of the software. This feature is typically self-contained enough, either in the amount of code that implements it or in the general idea that describes it, to warrant its independent testing. Given this, test cases are very fine-grained, but they attempt to group similar smaller tests which are semantically related. A test case is defined by three components regardless of the language it is implemented in: a header, a body and a cleanup routine. The header is, basically, a declarative piece of code that defines several properties to describe what the test case does and how it behaves. In other words: it defines the test case's meta-data, further described in the Meta-data section. The body is the test case itself. It executes all actions needed to reproduce the test, and checks for failures. This body is only executed if the abstract conditions specified by the header are met. The cleanup routine is a piece of code always executed after the body, regardless of the exit status of the test case. It can be used to undo side-effects of the test case. Note that almost all side-effects of a test case are automatically cleaned up by the library; this is explained in more detail in the rest of this document. It is extremely important to keep the separation between a test case's header and body well-defined, because the header is always parsed, whereas the body is only executed when the conditions defined in the header are met and when the user specifies that test case. At last, test cases are always contained into test programs. The test programs act as a front-end to them, providing a consistent interface to the user and several APIs to ease their implementation. ResultsUpon termination, a test case reports a status and, optionally, a textual reason describing why the test reported such status. The caller must ensure that the test case really performed the task that its status describes, as the test program may be bogus and therefore providing a misleading result, e.g., providing a result that indicates success but the error code of the program says otherwise. The possible exit status of a test case are one of the following:
The usefulness of the ‘expected_*’ results comes when writing test cases that verify known failures caused, in general, due to programming errors (aka bugs). Whenever the faulty condition that the ‘expected_*’ result is trying to cover is fixed, then the test case will be reported as ‘failed’ and the developer will have to adjust it to match its new condition. It is important to note that all ‘expected_*’ results are only provided as a hint to the caller; the caller must verify that the test case did actually terminate as the expected condition says. Input/outputTest cases are free to print whatever they want to their stdout(4) and stderr(4) file descriptors. They are, in fact, encouraged to print status information as they execute to keep the user informed of their actions. This is specially important for long test cases. Test cases will log their results to an auxiliary file, which is then collected by the test program they are contained in. The developer need not care about this as long as he uses the correct APIs to implement the test cases. The standard input of the test cases is unconditionally connected to ‘/dev/zero’. Meta-dataThe following metadata properties can be exposed via the test case's head:
EnvironmentEvery time a test case is executed, several environment variables are cleared or reseted to sane values to ensure they do not make the test fail due to unexpected conditions. These variables are:
Work directoriesThe test program always creates a temporary directory and switches to it before running the test case's body. This way the test case is free to modify its current directory as it wishes, and the runtime engine will be able to clean it up later on in a safe way, removing any traces of its execution from the system. To do so, the runtime engine will perform a recursive removal of the work directory without crossing mount points; if a mount point is found, the file system will be unmounted (if possible). File creation mode mask (umask)Test cases are always executed with a file creation mode mask (umask) of ‘0022’. The test case's code is free to change this during execution. SEE ALSO
|