A test consists of a set of test cases. Each test case is implemented as an erlang function. An erlang module implementing one or more test cases is called a test suite.
A test specification is a specification of which test suites and test cases to run and which to skip. A test specification can also group several test cases into conf cases with init and cleanup functions (see section about configuration cases below). In a test there can be test specifications on three different levels:
The top level is a test specification file which roughly specifies what to test for a whole application. The test specification in such a file is encapsulated in a topcase command.
Then there is a test specification for each test suite,
specifying which test cases to run within the suite. The test
specification for a test suite is returned from the
And finally there can be a test specification per test case, specifying sub test cases to run. The test specification for a test case is returned from the specification clause of the test case.
When a test starts, the total test specification is built in a tree fashion, starting from the top level test specification.
The following are the valid elements of a test specification. The specification can be one of these elements or a list with any combination of the elements:
A test specification file is a text file containing the top level test specification (a topcase command), and possibly one or more additional commands. A "command" in a test specification file means a key-value tuple ended by a dot-newline sequence.
The following commands are valid:
All test specification files shall have the extension ".spec". If special test specification files are needed for Windows or VxWorks platforms, additional files with the extension ".spec.win" and ".spec.vxworks" shall be used. This is useful e.g. if some test cases shall be skipped on these platforms.
Some examples for test specification files can be found in the Examples section of this user's guide.
If a group of test cases need the same initialization, a so called configuration or conf case can be used. A conf case consists of an initialization function, the group of test cases needing this initialization and a cleanup or finalization function.
If the init function in a conf case fails or returns
Both the init function and the cleanup function in a conf case
get the
If the
The optional
Properties = [parallel | sequence | Shuffle | {RepeatType,N}]
Shuffle = shuffle | {shuffle,Seed}
Seed = {integer(),integer(),integer()}
RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail |
repeat_until_any_ok | repeat_until_any_fail
N = integer() | forever
If the
Properties may be combined so that e.g. if
The properties for a conf case is always printed on the top of the HTML log for the group's init function. Also, the total execution time for a conf case can be found at the bottom of the log for the group's end function.
Configuration cases may be nested so that sets of grouped cases can be configured with the same init- and end functions.
If a conf case has a parallel property, its test cases will be spawned simultaneously and get executed in parallel. A test case is not allowed to execute in parallel with the end function however, which means that the time it takes to execute a set of parallel cases is equal to the execution time of the slowest test case in the group. A negative side effect of running test cases in parallel is that the HTML summary pages are not updated with links to the individual test case logs until the end function for the conf case has finished.
A conf case nested under a parallel conf case will start executing in parallel with previous (parallel) test cases (no matter what properties the nested conf case has). Since, however, test cases are never executed in parallel with the init- or the end function of the same conf case, it's only after a nested group of cases has finished that any remaining parallel cases in the previous conf case get spawned.
A conf case may be repeated a certain number of times
(specified by an integer) or indefinitely (specified by
It is possible to return the status of a conf case (ok or
failed), to affect the execution of the conf case on the level above.
This is accomplished by, in the end function, looking up the value
of
The
Here's an example of how to return the status from a conf case:
conf_end_function(Config) ->
Status = ?config(tc_group_result, Config),
case proplists:get_value(failed, Status) of
[] -> % no failed cases
{return_group_result,ok};
_Failed -> % one or more failed
{return_group_result,failed}
end.
It is also possible in the end function to check the status of
a nested conf case (maybe to determine what status the current conf case should
return). This is as simple as illustrated in the example above, only the
name of the end function of the nested conf case is stored in a tuple
conf_end_function_X(Config) ->
Status = ?config(tc_group_result, Config),
Failed = proplists:get_value(failed, Status),
case lists:member({group_result,conf_end_function_Y}, Failed) of
true ->
{return_group_result,failed};
false ->
{return_group_result,ok}
end;
...
When a conf case is repeated, the init- and end functions are also always called with each repetition.
The order that test cases in a conf case are executed, is under normal
circumstances the same as the order defined in the test specification.
With the
The user may provide a seed value (a tuple of three integers) with
the shuffle property:
If execution of a conf case with shuffled test cases is repeated, the seed will not be reset in between turns.
If a nested conf case is specified in a conf case with a
It is possible to skip certain test cases, for example if you know beforehand that a specific test case fails. This might be functionality which isn't yet implemented, a bug that is known but not yet fixed or some functionality which doesn't work or isn't applicable on a specific platform.
There are several different ways to state that a test case should be skipped:
The latter of course means that the execution clause is actually called, so the author must make sure that the test case is not run. For more information about the different clauses in a test case, see the chapter about writing test cases.
When a test case is skipped, it will be noted as