Information Technology Reference
In-Depth Information
2.1
Contract-Based Unit Testing for O-O Programs
In O-O programs, a unit test can be assimilated to a routine (method) call on an instance
using previously created instances as arguments. Test engineers write unit tests and
check that the result of calls are equal to pre-calculated values. In a Hoare-triple style
this means that a unit test can be modelled as (
v
,
o
,
o 1 ,... are variables,
init o ,
init o 1 ...
expressions that return instances,
m
the routine called, and
v 0 avalue):
{}o := init o ; o 1 := init o 1 ; ... ; v := o.m ( o 1 , ..., o n ) {v = v 0 }
In a contract-enabled environment, routines are equipped with contracts from the start:
{Pre}o.m ( o 1 , ..., o n ) {Post}
Unit tests can rely on contracts to check the validity of the call. It then consists only of
writing the code to initialize instances that would satisfy the precondition of the routine:
{}o := init o ; o 1 := init o 1 ; ...{Pre}
In this article we use contract-based automated random testing. In such an approach the
testing infrastructure automatically takes care of this last part. In practice, it generates
the sequence of instructions at random and proceeds with the call.
When making a call, if the generated instances do not satisfy the precondition of the
routine, the result of the call is ignored and not counted as a test. After the precondition
is checked, any contract violation or any exception triggered in the actual call then
corresponds to a failure in the program.
As the random testing tool is not able to avoid executing similar test cases, it might
uncover the same failure multiple times. Thus, it maps failures to faults by defining a
fault as a unique triple:
< m, line number of the failure, type of exception >
When tests are executed, branch coverage is calculated in a straightforward manner
as:
Branch Coverage = Number of exercised branches
Number of branches
2.2
The AutoTest Tool
This section presents a general view of how AutoTest works. More detailed explanations
on AutoTest are available in previous publications [4].
AutoTest is a tool implementing a random testing strategy for Eiffel and is integrated
to EiffelStudio 6.3 [2]. Given a set of classes and a time frame, AutoTest tries to test all
their public routines in the time frame.
 
Search WWH ::




Custom Search