Automatically Repairing Test Cases for Evolving
Method Declarations
Mehdi Mirzaaghaei
†
, Fabrizio Pastore
†
, Mauro Pezz` e
†‡
†
University of Lugano, Lugano, Switzerland
‡
University of Milano Bicocca, Milano, Italy
Email: {mehdi.mirzaaghaei,fabrizio.pastore,mauro.pezze}@usi.ch
Abstract—When software systems evolve, for example due to
fault fixes, modification of functionalities or refactoring activities,
test cases may become obsolete thus generating wrong results or
even not being executable or compilable. Maintaining test cases is
expensive and time consuming, and often test cases are discarded
by software developers due to high maintenance costs.
This paper presents TestCareAssistant, a technique that com-
bines data-flow analysis with program diffing for automatically
repairing test cases that become obsolete because of changes in
method declarations (addition, removal, or type modification of
parameters or return values). The paper illustrates the efficacy of
TestCareAssistant by analyzing the impact of method declarations
changes on the executability of test cases, and by presenting the
preliminary results of applying TestCareAssistant to repair 22 test
cases.
I. I NTRODUCTION
Software systems undergo several changes in their lifetime.
After the modifications, software engineers re-execute the test
cases to identify regressions in the existing functionalities [9].
Unfortunately test cases become obsolete and quickly unusable
if not maintained along with the system [1]. Common exam-
ples are test cases that do not compile because of changes
in method signatures, test scripts that do not execute due to
modifications of component APIs, or test cases that do not
reveal failures after changes in the specifications.
In the last years several researchers have studied the prob-
lem of automatically identifying and correcting obsolete test
cases. Some groups focused on GUI test cases. Xie et al. de-
veloped some techniques to automatically identify and correct
graphical objects affected by GUI changes [20], [8]. Jiang et
al. and Memon addressed generic problems like correcting
sequences of test scripts, for instance, pressing buttons or
invoking methods [15], [12]. Such techniques require accurate
system specifications or oracles. Daniel et al. focused on
automatically repairing test oracles [3], [2]. These techniques
solve important problems related to test maintenance activities
that span from repairing GUI test cases, test scripts, and
oracles.
In this paper, we deal with the problem of test evolution
with particular emphasis on test case compilation errors that
depend on changes in parameters or return values, for example
due to refactoring of the target system. Some changes of
these kind are automatically managed by refactoring tech-
niques [16]. Existing refactoring techniques can prevent simple
errors by automating some of the possible refactoring activities
like moving or renaming methods, modifying class hierar-
chies [18], or improving concurrency [5] or reentrancy [19].
Common refactoring practices like adding new parameters to
methods [21] are only partially automated by existing tools
and techniques. For example, ReBa [6] and Eclipse
1
avoid
compilation errors caused by parameter changes only when
the modified parameters can be replaced by default values.
Empirical studies indicate that 93% of the changes of param-
eters and return values are performed manually by software
developers [17], and this limits the practical applicability of
existing techniques. Although current techniques can cope
with simple cases, the problem of automatically repairing test
case compilation errors is still open.
This paper presents TestCareAssistant (TcA), a technique
that automatically repairs test compilation errors caused by
changes in the declaration of method parameters and return
values, focusing in particular on insertion and removal and
type changes. TcA automatically modifies test cases and adapts
the parameters according to the modified methods to repair
the test case and preserve its behavior. For example if a new
parameter is added to a method used in a test case, TcA
automatically creates and initializes the objects to be passed
to the method.
TcA applies both to pure refactoring that involves only
changes that do not alter software behavior, and floss refactor-
ing that combines refactoring and functional changes, which
is a software development practice more frequent than pure
refactoring [17]. TcA assumes only that the original function-
ality is preserved for the given test inputs.
TcA deals with changes that cause compilation errors, thus
ignores changes like the addition of a return value, and repairs
errors that are not currently fixed by existing refactoring tools,
which focus only on simple compilation problems like the
ones caused by method renaming or changes in the order of
parameters.
This paper contributes to the state-of-the-art by:
• introducing TestCareAssistant a technique to repair com-
pilation errors caused by changes in the declaration of
parameters and return values;
• analyzing 262 versions of 22 open source systems to
1
www.eclipse.org
978-1-4244-8628-1/10/$26.00 ©2010 IEEE
26th IEEE International Conference on Software Maintenance in Timi șoara, Romania