constraint inconsistency is detected only when all
the variables are instantiated. In some examples,
backward reasoning is not used for improving the
time required to generate test data (
sorted list
and
Voter
). However, on these examples, one can see that
backward reasoning does not slow down the process.
On other example, backward reasoning is useful and
improve the CPU time required to generate test data.
In conclusion, these experiments show firstly, that
constraints helps to find test data for testing proper-
ties, especially when random generation fails. Sec-
ondly, the choice of using operators like
match
to-
gether with forward and backward reasoning rules
speeds up the computation of a solution. An Pro-
log choice points implementation is ineffective when
there are numerous execution paths in a program.
6 RELATED WORK
Using constraint solving techniques to generate test
cases is not a new idea. (Dick and Faivre, 1993) and
(Marre, 1991) were among the first to introduce Con-
straint Logic Programming for generating test cases
from specification models such as VDM or algebraic
specifications. These seminal works yield the devel-
opment of GATEL, a tool that generates test cases for
reactive programs written in Lustre. In 1998, Gotlieb
et al. proposed using constraint techniques to gen-
erate test data for C programs (Gotlieb et al., 1998).
This approach was implemented in tools InKa and
Euclide (Gotlieb, 2009). In (Legeard and Peureux,
2001) set solving techniques were proposed to gen-
erate test cases from B models. These ideas were
pushed further through the development of the BZ-
TT and JML-TT toolset. In 2001, Pretschner devel-
oped the model-based test case generator AUTOFO-
CUS that exploited search strategies within constraint
logic programming (Pretschner, 2001) and recently,
PathCrawler introduced dynamic path-oriented test
data generation (Williams et al., 2005). This method
was independently discovered in the DART/CUTE
approach (Godefroid et al., 2005; Sen et al., 2005).
In the case of testing functional programs,
most approaches derive from the QuickCheck tool
(Claessen and Hughes, 2000) which generates test
data at random. GAST is a similar implementation
for Clean, while EasyCheck implements random test
data generation for Curry (Christiansen and Fischer,
2008). QuickCheck and GAST implement function
generators for higher-order function since they deal
with higher-order properties while this is not neces-
sary in our approach because such properties are not
allowed in Focalize. Easycheck resembles to FocaTe-
st because it takes advantage of the original language
features such as free variable and narrowing to gen-
erate automatically test cases w.r.t. a property. These
features could be related to clause definition, back-
tracking and labeling in CLP(FD) program without
constraint aspects. FocalTest originally takes inspira-
tions from these tools, that is, to test a functional pro-
gram against a property. As far as we know, FocalTest
is the first application of constraint solving in the area
of test data generation for functional programs.
The development of SAT-based constraint solver
for generating test data from declarative models also
yields the development of Kato (Uzuncaova and
Khurshid, 2008) that optimizes constraint solving
with (Alloy) model slicing. Like some of the above
tools such as GATEL, AUTOFOCUS or EUCLIDE,
FocalTest relies on finite domains constraint solving
techniques. But, it has two main differences with
these approaches. Firstly, it is integrated within a
environment which contains naturally property that
could be used for testing. Secondly, it uses its ownop-
erators implementation for generating test data in the
presence of conditionals and pattern-matching opera-
tions and concrete type. This allows various deduc-
tion rules to be exploited to find test data that satisfy
properties. Unlike traditional generate-and-test ap-
proaches, this allows one to exploit constraints to in-
fer new domain reductions and then helps the process
to converge more quickly towards sought solutions.
7 CONCLUSIONS
The constraint-based approach we proposed is a gen-
eral one that allows us to obtain an MC/DC compli-
ant test suite that satisfies the precondition part of Fo-
calize properties. This approach is based on a sys-
tematic translation of Focalize program into CLP(FD)
programs and relies on the definition of efficient con-
straint combinators to tackle pattern-matching and
higher-order functions. We integrated this constraint-
reasoning to FocalTest and relieves it from using in-
efficient generate-and-test approaches to select test
data satisfying given preconditions. Our experimen-
tal evaluation shows that using constraint reasoning
for this task outperforms traditional random test data
generation by a factor of 23.
Furthermore this work can be reused for test gen-
eration in other functional languages, for example to
extend test selection in QuickCheck-like tools (that
rely on random or user-guided generation). Further-
more exploring how the constraint model of the over-
all properties and programs could be used to formally
prove the conformance of the program to its specifica-
ICSOFT 2010 - 5th International Conference on Software and Data Technologies
90