SlideShare a Scribd company logo
Automatically
RepairingTest Cases
for Evolving Method Declarations
Mehdi Mirzaaghaei
Fabrizio Pastore
Mauro Pezzè
Università
della
Svizzera
italiana
http://swiss-landmarks.ch/panos/Lugano9.jpg
Software evolves
public class BankAccount {
	 private int balance;
	 public void deposit(int cents){
	 balance += cents;
	 }
	 public int getBalance(){
return balance
};
}
Software evolves
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals( 500, account.getBalance());
}
public class BankAccount {
	 private int balance;
	 public void deposit(int cents){
	 balance += cents;
	 }
	 public int getBalance(){
return balance
};
}
Software evolves
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals( 500, account.getBalance());
}
public class BankAccount {
	 private int balance;
	 public void deposit(int cents){
	 balance += cents;
	 }
	 public int getBalance(){
return balance
};
}
Software evolves
public class .....
public class AccountUtil {
	 private double dailyInterestRate = 0.00005;
	 private int interestTerm=365;
	
	 public double interest(BankAccount account
return account.getBalance()
*dailyInterestRate*interestTerm;
	 }
...
public class AccountFactory {
	 public static BankAccount create( AccountContext ctx, boolean special ){
	 	 BankAccount account = new BankAcccount( ctx.amount );
	 	 if ( special ){
	 	 	 account.setInterestRate(0.0001);
	 	 }
	 ...
public class .....
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals( 500, account.getBalance());
}
public class BankAccount {
	 private int balance;
	 public void deposit(int cents){
	 balance += cents;
	 }
	 public int getBalance(){
return balance
};
}
Software evolves
public class BankAccount {
	 private int balance;
	 public void deposit(int cents){
	 balance += cents;
	 }
	 public int getBalance(){
return balance
};
}
public class BankAccount {
	 private int balance;
	 public void deposit(Money money){
	 balance += money.centsValue;
	 }
	 public int getBalance(){
return balance;
};
}
Original classes are modified
public class .....
public class .....
Test cases need maintenance
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals( 500, account.getBalance());
}
public class BankAccount {
	 private int balance;
	 public void deposit(int cents){
	 balance += cents;
	 }
	 public int getBalance(){
return balance
};
}
public class BankAccount {
	 private int balance;
	 public void deposit(Money money){
	 balance += money.centsValue;
	 }
	 public int getBalance(){
return balance;
};
}
Compilation error:
Method deposit(Money) in the type
BankAccount is not applicable for
the arguments (int)
changes in method declarations:
23% changes
that impact on compilation
changes in method declarations:
23% changes
that impact on compilation
> 80% in maintenance releases
changes in method declarations:
23% changes
that impact on compilation
> 80% in maintenance releases
Automatic Repair to Save Effort
AutomaticTest Repair
[Memon et. al. 2008, Grechanik 2009 ]
Repair GUI tests
Well suited only for GUI tests
AutomaticTest Repair
[Memon et. al. 2008, Grechanik 2009 ]
Repair GUI tests Repair Oracles
[B. Daniel et al 2010]
testInterest(){
...
assertEquals( 50, result );
}
FAILURE: expected 50, found: 40
assertEquals( 40, result );
Well suited only for GUI tests Focus on oracles only
AutomaticTest Repair
[Memon et. al. 2008, Grechanik 2009 ]
Repair GUI tests
Refactoring Techniques
[ReBa, Eclipse]
Repair Oracles
[B. Daniel et al 2010]
testInterest(){
...
assertEquals( 50, result );
}
FAILURE: expected 50, found: 40
assertEquals( 40, result );
//calculate one year interest
result = account.interest();
result = account.interest( 0 );
Well suited only for GUI tests Focus on oracles only
Prevent only some compilation errors
AutomaticTest Repair
TestCareAssistant
repairs test case compilation errors
• Parameter add
• Parameter type change • Return type change
• Parameter remove
caused by method declaration changes
TestCareAssistant
repairs test case compilation errors
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals(500, account.getBalance());
• Parameter add
• Parameter type change • Return type change
• Parameter remove
caused by method declaration changes
TestCareAssistant
repairs test case compilation errors
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals(500, account.getBalance());
Replace:
int amount = 500;
with:
Money amount = new Money(500);
account.deposit(amount);
• Parameter add
• Parameter type change • Return type change
• Parameter remove
caused by method declaration changes
TestCareAssistant
repairs test case compilation errors
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals(500, account.getBalance());
testDeposit(){
BankAccount account = new BankAccount();
Money amount = new Money(500);
account.deposit(amount);
assertEquals(500, account.getBalance());
Replace:
int amount = 500;
with:
Money amount = new Money(500);
account.deposit(amount);
• Parameter add
• Parameter type change • Return type change
• Parameter remove
caused by method declaration changes
TestCareAssistant
repairs test case compilation errors
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals(500, account.getBalance());
testDeposit(){
BankAccount account = new BankAccount();
Money amount = new Money(500);
account.deposit(amount);
assertEquals(500, account.getBalance());
Replace:
int amount = 500;
with:
Money amount = new Money(500);
account.deposit(amount);
• Parameter add
• Parameter type change • Return type change
• Parameter remove
caused by method declaration changes
TestCareAssistant
repairs test case compilation errors
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals(500, account.getBalance());
testDeposit(){
BankAccount account = new BankAccount();
Money amount = new Money(500);
account.deposit(amount);
assertEquals(500, account.getBalance());
Replace:
int amount = 500;
with:
Money amount = new Money(500);
account.deposit(amount);
• Parameter add
• Parameter type change • Return type change
• Parameter remove
caused by method declaration changes
TestCareAssistant
repairs test case compilation errors
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals(500, account.getBalance());
testDeposit(){
BankAccount account = new BankAccount();
Money amount = new Money(500);
account.deposit(amount);
assertEquals(500, account.getBalance());
Replace:
int amount = 500;
with:
Money amount = new Money(500);
account.deposit(amount);
• Parameter add
• Parameter type change • Return type change
• Parameter remove
caused by method declaration changes
Repair parameter type change
public class BankAccount {
	 private int balance;
	 public void deposit(int cents){
	 balance += cents;
	 }
	 public int getBalance(){
return balance;
}
}
public class BankAccount {
	 private int balance;
	 public void deposit(Money money){
balance += money.CentsValue;
	 }
	 public int getBalance(){
return balance;
}
}
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals( 500, account.getBalance());
}
Version 0 Version 1
Which parameter to initialize?
public class BankAccount {
	 private int balance;
	 public void deposit(int cents){
	 balance += cents;
	 }
	 public int getBalance(){
return balance;
}
}
public class BankAccount {
	 private int balance;
	 public void deposit(Money money){
balance += money.CentsValue;
	 }
	 public int getBalance(){
return balance;
}
}
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals( 500, account.getBalance());
}
Version 0 Version 1
Which parameter to initialize?
Use code diff to identify the parameter1
public class BankAccount {
	 private int balance;
	 public void deposit(int cents){
	 balance += cents;
	 }
	 public int getBalance(){
return balance;
}
}
public class BankAccount {
	 private int balance;
	 public void deposit(Money money){
balance += money.CentsValue;
	 }
	 public int getBalance(){
return balance;
}
}
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals( 500, account.getBalance());
}
Version 0 Version 1
How to initialize a complex object?
public class BankAccount {
	 private int balance;
	 public void deposit(int cents){
	 balance += cents;
	 }
	 public int getBalance(){
return balance;
}
}
public class BankAccount {
	 private int balance;
	 public void deposit(Money money){
balance += money.centsValue;
	 }
	 public int getBalance(){
return balance;
}
}
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals( 500, account.getBalance());
}
Version 0 Version 1
How to initialize a complex object?
Find first uses of parameter fields inVersion12
public class BankAccount {
	 private int balance;
	 public void deposit(int cents){
	 balance += cents;
	 }
	 public int getBalance(){
return balance;
}
}
public class BankAccount {
	 private int balance;
	 public void deposit(Money money){
balance += money.centsValue;
	 }
	 public int getBalance(){
return balance;
}
}
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals( 500, account.getBalance());
}
Version 0 Version 1
How to determine fields values?
public class BankAccount {
	 private int balance;
	 public void deposit(int cents){
	 balance += cents;
	 }
	 public int getBalance(){
return balance;
}
}
public class BankAccount {
	 private int balance;
	 public void deposit(Money money){
balance += money.centsValue;
	 }
	 public int getBalance(){
return balance;
}
}
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals( 500, account.getBalance());
}
Version 0 Version 1
How to determine fields values?
Diff to identify corresponding variable inVersion 03
public class BankAccount {
	 private int balance;
	 public void deposit(int cents){
	 balance += cents;
	 }
	 public int getBalance(){
return balance;
}
}
public class BankAccount {
	 private int balance;
	 public void deposit(Money money){
balance += money.centsValue;
	 }
	 public int getBalance(){
return balance;
}
}
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals( 500, account.getBalance());
}
Version 0 Version 1
What was the original value?
public class BankAccount {
	 private int balance;
	 public void deposit(int cents){
	 balance += cents;
	 }
	 public int getBalance(){
return balance;
}
}
public class BankAccount {
	 private int balance;
	 public void deposit(Money money){
balance += money.CentsValue;
	 }
	 public int getBalance(){
return balance;
}
}
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals( 500, account.getBalance());
}
Version 0 Version 1
What was the original value?
Analyze the def-use chain of the variable back to
the definition in the test4
public class BankAccount {
	 private int balance;
	 public void deposit(int cents){
	 balance += cents;
	 }
	 public int getBalance(){
return balance;
}
}
public class BankAccount {
	 private int balance;
	 public void deposit(Money money){
balance += money.CentsValue;
	 }
	 public int getBalance(){
return balance;
}
}
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals( 500, account.getBalance());
}
Version 0 Version 1
What was the original value?
Analyze the def-use chain of the variable back to
the definition in the test4
public class BankAccount {
	 private int balance;
	 public void deposit(int cents){
	 balance += cents;
	 }
	 public int getBalance(){
return balance;
}
}
public class BankAccount {
	 private int balance;
	 public void deposit(Money money){
balance += money.CentsValue;
	 }
	 public int getBalance(){
return balance;
}
}
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals( 500, account.getBalance());
}
Version 0 Version 1
How can we repair the test?
public class BankAccount {
	 private int balance;
	 public void deposit(int cents){
	 balance += cents;
	 }
	 public int getBalance(){
return balance;
}
}
public class BankAccount {
	 private int balance;
	 public void deposit(Money money){
balance += money.centsValue;
	 }
	 public int getBalance(){
return balance;
}
}
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals( 500, account.getBalance());
}
Version 0 Version 1
How can we repair the test?
public class BankAccount {
	 private int balance;
	 public void deposit(int cents){
	 balance += cents;
	 }
	 public int getBalance(){
return balance;
}
}
public class BankAccount {
	 private int balance;
	 public void deposit(Money money){
balance += money.centsValue;
	 }
	 public int getBalance(){
return balance;
}
}
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals( 500, account.getBalance());
}
Version 0 Version 1
How can we repair the test?
Instantiate the new object,
use original values to initialize fields5
public class BankAccount {
	 private int balance;
	 public void deposit(int cents){
	 balance += cents;
	 }
	 public int getBalance(){
return balance;
}
}
public class BankAccount {
	 private int balance;
	 public void deposit(Money money){
balance += money.centsValue;
	 }
	 public int getBalance(){
return balance;
}
}
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals( 500, account.getBalance());
}
Version 0 Version 1
How can we repair the test?
Instantiate the new object,
use original values to initialize fields5
Replace:
int amount = 500;
with:
Money amount = new Money(500);
account.deposit(amount);
public class BankAccount {
	 private int balance;
	 public void deposit(int cents){
	 balance += cents;
	 }
	 public int getBalance(){
return balance;
}
}
public class BankAccount {
	 private int balance;
	 public void deposit(Money money){
balance += money.centsValue;
	 }
	 public int getBalance(){
return balance;
}
}
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals( 500, account.getBalance());
}
Version 0 Version 1
To what extentTestCareAssistant can
fix test cases automatically?
To what extentTestCareAssistant can
fix test cases automatically?
• Repair 22 test cases of 6 open source systems
• Continuum, Geronimo, xml-security, PMD, POI, Shindig
• 24 compilation errors caused by different changes
• 9 parameter types changed, 8 parameters added, 3 parameters
removed, 4 return types changed
To what extentTestCareAssistant can
fix test cases automatically?
Results Total Repaired %
Test Cases 22 16 72
Compilation Errors 24 18 75
Values Initialized 36 29 80
• Repair 22 test cases of 6 open source systems
• Continuum, Geronimo, xml-security, PMD, POI, Shindig
• 24 compilation errors caused by different changes
• 9 parameter types changed, 8 parameters added, 3 parameters
removed, 4 return types changed
To what extentTestCareAssistant can
fix test cases automatically?
Results Total Repaired %
Test Cases 22 16 72
Compilation Errors 24 18 75
Values Initialized 36 29 80
• Repair 22 test cases of 6 open source systems
• Continuum, Geronimo, xml-security, PMD, POI, Shindig
• 24 compilation errors caused by different changes
• 9 parameter types changed, 8 parameters added, 3 parameters
removed, 4 return types changed
To what extentTestCareAssistant can
fix test cases automatically?
• Static data flow analysis not always effective
• Use of complex data structures, e.g. hash tables
• Changes in method logic
• Changes in interfaces
Results Total Repaired %
Test Cases 22 16 72
Compilation Errors 24 18 75
Conclusions
public class BankAccount {
	 public void deposit(int cents){
	 balance += cents;
	 }
}
public class BankAccount {
	 public void deposit(Money money){
balance += money.CentsValue;
	 }
}
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals(500, account.getBalance());
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals(500, account.getBalance());
Conclusions
public class BankAccount {
	 public void deposit(int cents){
	 balance += cents;
	 }
}
public class BankAccount {
	 public void deposit(Money money){
balance += money.CentsValue;
	 }
}
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals(500, account.getBalance());
testDeposit(){
BankAccount account = new BankAccount();
Money amount = new Money(500);
account.deposit(amount);
assertEquals(500, account.getBalance());
Conclusions
public class BankAccount {
	 public void deposit(int cents){
	 balance += cents;
	 }
}
public class BankAccount {
	 public void deposit(Money money){
balance += money.CentsValue;
	 }
}
Replace:
int amount = 500;
with:
Money amount = new Money(500);
account.deposit(amount);
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals(500, account.getBalance());
testDeposit(){
BankAccount account = new BankAccount();
Money amount = new Money(500);
account.deposit(amount);
assertEquals(500, account.getBalance());
TestCareAssistant
Future Work
CopticChronology EthiopicChronology
Chronology
+ withUTC()
TestCopticUTC(){
....
assertEquals("AM",
copticChronology.withUTC() );
}
Future Work
CopticChronology EthiopicChronology
Chronology
+ withUTC()
TestCopticUTC(){
....
assertEquals("AM",
copticChronology.withUTC() );
}
TestEthiopicUTC(){
....
assertEquals("EE",
ethiopicChronology.withUTC()
}
CopticChronology EthiopicChronology
Chronology
+ withUTC()
Future Work
CopticChronology EthiopicChronology
Chronology
+ withUTC()
TestCopticUTC(){
....
assertEquals("AM",
copticChronology.withUTC() );
}
TestEthiopicUTC(){
....
assertEquals("EE",
ethiopicChronology.withUTC()
}
CopticChronology EthiopicChronology
Chronology
+ withUTC()
Future Work
CopticChronology EthiopicChronology
Chronology
+ withUTC()
TestCopticUTC(){
....
assertEquals("AM",
copticChronology.withUTC() );
}
TestEthiopicUTC(){
....
assertEquals("EE",
ethiopicChronology.withUTC()
}
CopticChronology EthiopicChronology
Chronology
+ withUTC()
AutomateTest Generation by Identifying and
ImplementingTest Adaptation Patterns
Questions?
public class BankAccount {
	 public void deposit(int cents){
	 balance += cents;
	 }
}
public class BankAccount {
	 public void deposit(Money money){
balance += money.CentsValue;
	 }
}
Replace:
int amount = 500;
with:
Money amount = new Money(500);
account.deposit(amount);
testDeposit(){
BankAccount account = new BankAccount();
int amount = 500;
account.deposit(amount);
assertEquals(500, account.getBalance());
testDeposit(){
BankAccount account = new BankAccount();
Money amount = new Money(500);
account.deposit(amount);
assertEquals(500, account.getBalance());
TestCareAssistant

More Related Content

DOC
Marcus Portfolio
PDF
Declaring friend function with inline code
PDF
IP project for class 12 cbse
ODP
Simple design/programming nuggets
PPTX
C programming
DOCX
informatics practices practical file
PDF
Por qué usar Spock en lugar de JUnit / Mockito para tus tests Java - Codemoti...
PPTX
Marcus Portfolio
Declaring friend function with inline code
IP project for class 12 cbse
Simple design/programming nuggets
C programming
informatics practices practical file
Por qué usar Spock en lugar de JUnit / Mockito para tus tests Java - Codemoti...

What's hot (19)

PPTX
Writing Good Tests
DOCX
VISUALIZAR REGISTROS EN UN JTABLE
DOC
Computer mai ns project
PDF
MaintainStaffTable
PPTX
Dompletion: DOM-Aware JavaScript Code Completion
PDF
Mutation Analysis for JavaScript Web Applicaiton Testing SEKE2013
PPTX
How Reactive do we need to be
DOC
Oops lab manual2
KEY
Clojure workshop
PDF
The biggest lies about react hooks
DOCX
INSERCION DE REGISTROS DESDE VISUAL.NET A UNA BD DE SQL SERVER
PDF
Java 2
PDF
Promise: async programming hero
PDF
Practical
PDF
Developer Experience i TypeScript. Najbardziej ikoniczne duo
PDF
Beautiful java script
PPTX
A Test of Strength
DOCX
Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...
PPTX
Unit testing patterns for concurrent code
Writing Good Tests
VISUALIZAR REGISTROS EN UN JTABLE
Computer mai ns project
MaintainStaffTable
Dompletion: DOM-Aware JavaScript Code Completion
Mutation Analysis for JavaScript Web Applicaiton Testing SEKE2013
How Reactive do we need to be
Oops lab manual2
Clojure workshop
The biggest lies about react hooks
INSERCION DE REGISTROS DESDE VISUAL.NET A UNA BD DE SQL SERVER
Java 2
Promise: async programming hero
Practical
Developer Experience i TypeScript. Najbardziej ikoniczne duo
Beautiful java script
A Test of Strength
Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...
Unit testing patterns for concurrent code
Ad

Viewers also liked (7)

PDF
ORASI Consulting Group Servicios
PPT
WorldCat Search API
PDF
GESTAR II - Aaa4 mat aluno
PDF
2011 Redin e Silveira - a condição camponesa revisitada - revista isegoria
PPT
Stemi2009
PPT
Gothic art
PPS
[R Mortimer] Uma Linda Ideia A Ser Imitada Som
ORASI Consulting Group Servicios
WorldCat Search API
GESTAR II - Aaa4 mat aluno
2011 Redin e Silveira - a condição camponesa revisitada - revista isegoria
Stemi2009
Gothic art
[R Mortimer] Uma Linda Ideia A Ser Imitada Som
Ad

Similar to Automatically Repairing Test Cases for Evolving Method Declarations (20)

PPTX
Dependency injection - the right way
PPTX
Practical approach for testing your software with php unit
PPT
Java: Class Design Examples
DOCX
1-What are the opportunities and threats that could impact the org
DOCX
1-What are the opportunities and threats that could impact the org
PDF
C++ Bank Account Error Fix, full code. I am using Dev-C++ to Compile.pdf
PDF
How to write clean tests
PDF
Change to oop formatimport java.util.Scanner;import java.io.;.pdf
PDF
TDD, BDD and mocks
DOCX
Tmpj3 01 201181102muhammad_tohir
PDF
Bank Program in JavaBelow is my code(havent finished, but it be .pdf
PDF
Bdd for-dso-1227123516572504-8
PDF
Account.h Definition of Account class. #ifndef ACCOUNT_H #d.pdf
PDF
Rajeev oops 2nd march
PDF
I need help creating a basic and simple Java program. Here is the ex.pdf
PDF
import java.util.Scanner;import java.text.DecimalFormat;import j.pdf
PDF
The java class Account that simultes the Account class.pdf
PDF
Droid on Chain - Berry Ventura Lev, Kik
DOCX
Write a banking program that simulates the operation of your local ba.docx
PDF
Code quailty metrics demystified
Dependency injection - the right way
Practical approach for testing your software with php unit
Java: Class Design Examples
1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org
C++ Bank Account Error Fix, full code. I am using Dev-C++ to Compile.pdf
How to write clean tests
Change to oop formatimport java.util.Scanner;import java.io.;.pdf
TDD, BDD and mocks
Tmpj3 01 201181102muhammad_tohir
Bank Program in JavaBelow is my code(havent finished, but it be .pdf
Bdd for-dso-1227123516572504-8
Account.h Definition of Account class. #ifndef ACCOUNT_H #d.pdf
Rajeev oops 2nd march
I need help creating a basic and simple Java program. Here is the ex.pdf
import java.util.Scanner;import java.text.DecimalFormat;import j.pdf
The java class Account that simultes the Account class.pdf
Droid on Chain - Berry Ventura Lev, Kik
Write a banking program that simulates the operation of your local ba.docx
Code quailty metrics demystified

More from ICSM 2010 (15)

PDF
A tree kernel based approach for clone detection
PPTX
Scalable Semantic Web-based Source Code Search Infrastructure
PDF
2D and 3D Visualizations In Wikidev2.0 M. Fokaefs, D. Serrano, B. Tansey and ...
PDF
Wiki dev nlp
PDF
iFL: An Interactive Environment for Understanding Feature Implementations
PDF
Using Clone Detection to Identify Bugs in Concurrent Software
PDF
Physical and Conceptual Identifier Dispersion: Measures and Relation to Fault...
PDF
Automated Identification of Cross-browser Issues in Web Applications
PDF
Reverse Engineering Object-Oriented Distributed Systems
PPTX
Software asset management
PPTX
Successfulresearch 100915022614-phpapp01
PPTX
Enabling multi tenancy(An Industrial Experience Report)
PDF
Ponsini automatic slides
PDF
Studying the impact of dependency network measures on software quality
PDF
Icsm2010 Announcement
A tree kernel based approach for clone detection
Scalable Semantic Web-based Source Code Search Infrastructure
2D and 3D Visualizations In Wikidev2.0 M. Fokaefs, D. Serrano, B. Tansey and ...
Wiki dev nlp
iFL: An Interactive Environment for Understanding Feature Implementations
Using Clone Detection to Identify Bugs in Concurrent Software
Physical and Conceptual Identifier Dispersion: Measures and Relation to Fault...
Automated Identification of Cross-browser Issues in Web Applications
Reverse Engineering Object-Oriented Distributed Systems
Software asset management
Successfulresearch 100915022614-phpapp01
Enabling multi tenancy(An Industrial Experience Report)
Ponsini automatic slides
Studying the impact of dependency network measures on software quality
Icsm2010 Announcement

Automatically Repairing Test Cases for Evolving Method Declarations

  • 1. Automatically RepairingTest Cases for Evolving Method Declarations Mehdi Mirzaaghaei Fabrizio Pastore Mauro Pezzè Università della Svizzera italiana http://swiss-landmarks.ch/panos/Lugano9.jpg
  • 3. public class BankAccount { private int balance; public void deposit(int cents){ balance += cents; } public int getBalance(){ return balance }; } Software evolves
  • 4. testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals( 500, account.getBalance()); } public class BankAccount { private int balance; public void deposit(int cents){ balance += cents; } public int getBalance(){ return balance }; } Software evolves
  • 5. testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals( 500, account.getBalance()); } public class BankAccount { private int balance; public void deposit(int cents){ balance += cents; } public int getBalance(){ return balance }; } Software evolves
  • 6. public class ..... public class AccountUtil { private double dailyInterestRate = 0.00005; private int interestTerm=365; public double interest(BankAccount account return account.getBalance() *dailyInterestRate*interestTerm; } ... public class AccountFactory { public static BankAccount create( AccountContext ctx, boolean special ){ BankAccount account = new BankAcccount( ctx.amount ); if ( special ){ account.setInterestRate(0.0001); } ... public class ..... testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals( 500, account.getBalance()); } public class BankAccount { private int balance; public void deposit(int cents){ balance += cents; } public int getBalance(){ return balance }; } Software evolves
  • 7. public class BankAccount { private int balance; public void deposit(int cents){ balance += cents; } public int getBalance(){ return balance }; } public class BankAccount { private int balance; public void deposit(Money money){ balance += money.centsValue; } public int getBalance(){ return balance; }; } Original classes are modified
  • 8. public class ..... public class ..... Test cases need maintenance testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals( 500, account.getBalance()); } public class BankAccount { private int balance; public void deposit(int cents){ balance += cents; } public int getBalance(){ return balance }; } public class BankAccount { private int balance; public void deposit(Money money){ balance += money.centsValue; } public int getBalance(){ return balance; }; } Compilation error: Method deposit(Money) in the type BankAccount is not applicable for the arguments (int)
  • 9. changes in method declarations: 23% changes that impact on compilation
  • 10. changes in method declarations: 23% changes that impact on compilation > 80% in maintenance releases
  • 11. changes in method declarations: 23% changes that impact on compilation > 80% in maintenance releases Automatic Repair to Save Effort
  • 13. [Memon et. al. 2008, Grechanik 2009 ] Repair GUI tests Well suited only for GUI tests AutomaticTest Repair
  • 14. [Memon et. al. 2008, Grechanik 2009 ] Repair GUI tests Repair Oracles [B. Daniel et al 2010] testInterest(){ ... assertEquals( 50, result ); } FAILURE: expected 50, found: 40 assertEquals( 40, result ); Well suited only for GUI tests Focus on oracles only AutomaticTest Repair
  • 15. [Memon et. al. 2008, Grechanik 2009 ] Repair GUI tests Refactoring Techniques [ReBa, Eclipse] Repair Oracles [B. Daniel et al 2010] testInterest(){ ... assertEquals( 50, result ); } FAILURE: expected 50, found: 40 assertEquals( 40, result ); //calculate one year interest result = account.interest(); result = account.interest( 0 ); Well suited only for GUI tests Focus on oracles only Prevent only some compilation errors AutomaticTest Repair
  • 16. TestCareAssistant repairs test case compilation errors • Parameter add • Parameter type change • Return type change • Parameter remove caused by method declaration changes
  • 17. TestCareAssistant repairs test case compilation errors testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals(500, account.getBalance()); • Parameter add • Parameter type change • Return type change • Parameter remove caused by method declaration changes
  • 18. TestCareAssistant repairs test case compilation errors testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals(500, account.getBalance()); Replace: int amount = 500; with: Money amount = new Money(500); account.deposit(amount); • Parameter add • Parameter type change • Return type change • Parameter remove caused by method declaration changes
  • 19. TestCareAssistant repairs test case compilation errors testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals(500, account.getBalance()); testDeposit(){ BankAccount account = new BankAccount(); Money amount = new Money(500); account.deposit(amount); assertEquals(500, account.getBalance()); Replace: int amount = 500; with: Money amount = new Money(500); account.deposit(amount); • Parameter add • Parameter type change • Return type change • Parameter remove caused by method declaration changes
  • 20. TestCareAssistant repairs test case compilation errors testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals(500, account.getBalance()); testDeposit(){ BankAccount account = new BankAccount(); Money amount = new Money(500); account.deposit(amount); assertEquals(500, account.getBalance()); Replace: int amount = 500; with: Money amount = new Money(500); account.deposit(amount); • Parameter add • Parameter type change • Return type change • Parameter remove caused by method declaration changes
  • 21. TestCareAssistant repairs test case compilation errors testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals(500, account.getBalance()); testDeposit(){ BankAccount account = new BankAccount(); Money amount = new Money(500); account.deposit(amount); assertEquals(500, account.getBalance()); Replace: int amount = 500; with: Money amount = new Money(500); account.deposit(amount); • Parameter add • Parameter type change • Return type change • Parameter remove caused by method declaration changes
  • 22. TestCareAssistant repairs test case compilation errors testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals(500, account.getBalance()); testDeposit(){ BankAccount account = new BankAccount(); Money amount = new Money(500); account.deposit(amount); assertEquals(500, account.getBalance()); Replace: int amount = 500; with: Money amount = new Money(500); account.deposit(amount); • Parameter add • Parameter type change • Return type change • Parameter remove caused by method declaration changes
  • 23. Repair parameter type change public class BankAccount { private int balance; public void deposit(int cents){ balance += cents; } public int getBalance(){ return balance; } } public class BankAccount { private int balance; public void deposit(Money money){ balance += money.CentsValue; } public int getBalance(){ return balance; } } testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals( 500, account.getBalance()); } Version 0 Version 1
  • 24. Which parameter to initialize? public class BankAccount { private int balance; public void deposit(int cents){ balance += cents; } public int getBalance(){ return balance; } } public class BankAccount { private int balance; public void deposit(Money money){ balance += money.CentsValue; } public int getBalance(){ return balance; } } testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals( 500, account.getBalance()); } Version 0 Version 1
  • 25. Which parameter to initialize? Use code diff to identify the parameter1 public class BankAccount { private int balance; public void deposit(int cents){ balance += cents; } public int getBalance(){ return balance; } } public class BankAccount { private int balance; public void deposit(Money money){ balance += money.CentsValue; } public int getBalance(){ return balance; } } testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals( 500, account.getBalance()); } Version 0 Version 1
  • 26. How to initialize a complex object? public class BankAccount { private int balance; public void deposit(int cents){ balance += cents; } public int getBalance(){ return balance; } } public class BankAccount { private int balance; public void deposit(Money money){ balance += money.centsValue; } public int getBalance(){ return balance; } } testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals( 500, account.getBalance()); } Version 0 Version 1
  • 27. How to initialize a complex object? Find first uses of parameter fields inVersion12 public class BankAccount { private int balance; public void deposit(int cents){ balance += cents; } public int getBalance(){ return balance; } } public class BankAccount { private int balance; public void deposit(Money money){ balance += money.centsValue; } public int getBalance(){ return balance; } } testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals( 500, account.getBalance()); } Version 0 Version 1
  • 28. How to determine fields values? public class BankAccount { private int balance; public void deposit(int cents){ balance += cents; } public int getBalance(){ return balance; } } public class BankAccount { private int balance; public void deposit(Money money){ balance += money.centsValue; } public int getBalance(){ return balance; } } testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals( 500, account.getBalance()); } Version 0 Version 1
  • 29. How to determine fields values? Diff to identify corresponding variable inVersion 03 public class BankAccount { private int balance; public void deposit(int cents){ balance += cents; } public int getBalance(){ return balance; } } public class BankAccount { private int balance; public void deposit(Money money){ balance += money.centsValue; } public int getBalance(){ return balance; } } testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals( 500, account.getBalance()); } Version 0 Version 1
  • 30. What was the original value? public class BankAccount { private int balance; public void deposit(int cents){ balance += cents; } public int getBalance(){ return balance; } } public class BankAccount { private int balance; public void deposit(Money money){ balance += money.CentsValue; } public int getBalance(){ return balance; } } testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals( 500, account.getBalance()); } Version 0 Version 1
  • 31. What was the original value? Analyze the def-use chain of the variable back to the definition in the test4 public class BankAccount { private int balance; public void deposit(int cents){ balance += cents; } public int getBalance(){ return balance; } } public class BankAccount { private int balance; public void deposit(Money money){ balance += money.CentsValue; } public int getBalance(){ return balance; } } testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals( 500, account.getBalance()); } Version 0 Version 1
  • 32. What was the original value? Analyze the def-use chain of the variable back to the definition in the test4 public class BankAccount { private int balance; public void deposit(int cents){ balance += cents; } public int getBalance(){ return balance; } } public class BankAccount { private int balance; public void deposit(Money money){ balance += money.CentsValue; } public int getBalance(){ return balance; } } testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals( 500, account.getBalance()); } Version 0 Version 1
  • 33. How can we repair the test? public class BankAccount { private int balance; public void deposit(int cents){ balance += cents; } public int getBalance(){ return balance; } } public class BankAccount { private int balance; public void deposit(Money money){ balance += money.centsValue; } public int getBalance(){ return balance; } } testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals( 500, account.getBalance()); } Version 0 Version 1
  • 34. How can we repair the test? public class BankAccount { private int balance; public void deposit(int cents){ balance += cents; } public int getBalance(){ return balance; } } public class BankAccount { private int balance; public void deposit(Money money){ balance += money.centsValue; } public int getBalance(){ return balance; } } testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals( 500, account.getBalance()); } Version 0 Version 1
  • 35. How can we repair the test? Instantiate the new object, use original values to initialize fields5 public class BankAccount { private int balance; public void deposit(int cents){ balance += cents; } public int getBalance(){ return balance; } } public class BankAccount { private int balance; public void deposit(Money money){ balance += money.centsValue; } public int getBalance(){ return balance; } } testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals( 500, account.getBalance()); } Version 0 Version 1
  • 36. How can we repair the test? Instantiate the new object, use original values to initialize fields5 Replace: int amount = 500; with: Money amount = new Money(500); account.deposit(amount); public class BankAccount { private int balance; public void deposit(int cents){ balance += cents; } public int getBalance(){ return balance; } } public class BankAccount { private int balance; public void deposit(Money money){ balance += money.centsValue; } public int getBalance(){ return balance; } } testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals( 500, account.getBalance()); } Version 0 Version 1
  • 37. To what extentTestCareAssistant can fix test cases automatically?
  • 38. To what extentTestCareAssistant can fix test cases automatically? • Repair 22 test cases of 6 open source systems • Continuum, Geronimo, xml-security, PMD, POI, Shindig • 24 compilation errors caused by different changes • 9 parameter types changed, 8 parameters added, 3 parameters removed, 4 return types changed
  • 39. To what extentTestCareAssistant can fix test cases automatically? Results Total Repaired % Test Cases 22 16 72 Compilation Errors 24 18 75 Values Initialized 36 29 80 • Repair 22 test cases of 6 open source systems • Continuum, Geronimo, xml-security, PMD, POI, Shindig • 24 compilation errors caused by different changes • 9 parameter types changed, 8 parameters added, 3 parameters removed, 4 return types changed
  • 40. To what extentTestCareAssistant can fix test cases automatically? Results Total Repaired % Test Cases 22 16 72 Compilation Errors 24 18 75 Values Initialized 36 29 80 • Repair 22 test cases of 6 open source systems • Continuum, Geronimo, xml-security, PMD, POI, Shindig • 24 compilation errors caused by different changes • 9 parameter types changed, 8 parameters added, 3 parameters removed, 4 return types changed
  • 41. To what extentTestCareAssistant can fix test cases automatically? • Static data flow analysis not always effective • Use of complex data structures, e.g. hash tables • Changes in method logic • Changes in interfaces Results Total Repaired % Test Cases 22 16 72 Compilation Errors 24 18 75
  • 42. Conclusions public class BankAccount { public void deposit(int cents){ balance += cents; } } public class BankAccount { public void deposit(Money money){ balance += money.CentsValue; } } testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals(500, account.getBalance()); testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals(500, account.getBalance());
  • 43. Conclusions public class BankAccount { public void deposit(int cents){ balance += cents; } } public class BankAccount { public void deposit(Money money){ balance += money.CentsValue; } } testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals(500, account.getBalance()); testDeposit(){ BankAccount account = new BankAccount(); Money amount = new Money(500); account.deposit(amount); assertEquals(500, account.getBalance());
  • 44. Conclusions public class BankAccount { public void deposit(int cents){ balance += cents; } } public class BankAccount { public void deposit(Money money){ balance += money.CentsValue; } } Replace: int amount = 500; with: Money amount = new Money(500); account.deposit(amount); testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals(500, account.getBalance()); testDeposit(){ BankAccount account = new BankAccount(); Money amount = new Money(500); account.deposit(amount); assertEquals(500, account.getBalance()); TestCareAssistant
  • 45. Future Work CopticChronology EthiopicChronology Chronology + withUTC() TestCopticUTC(){ .... assertEquals("AM", copticChronology.withUTC() ); }
  • 46. Future Work CopticChronology EthiopicChronology Chronology + withUTC() TestCopticUTC(){ .... assertEquals("AM", copticChronology.withUTC() ); } TestEthiopicUTC(){ .... assertEquals("EE", ethiopicChronology.withUTC() } CopticChronology EthiopicChronology Chronology + withUTC()
  • 47. Future Work CopticChronology EthiopicChronology Chronology + withUTC() TestCopticUTC(){ .... assertEquals("AM", copticChronology.withUTC() ); } TestEthiopicUTC(){ .... assertEquals("EE", ethiopicChronology.withUTC() } CopticChronology EthiopicChronology Chronology + withUTC()
  • 48. Future Work CopticChronology EthiopicChronology Chronology + withUTC() TestCopticUTC(){ .... assertEquals("AM", copticChronology.withUTC() ); } TestEthiopicUTC(){ .... assertEquals("EE", ethiopicChronology.withUTC() } CopticChronology EthiopicChronology Chronology + withUTC() AutomateTest Generation by Identifying and ImplementingTest Adaptation Patterns
  • 49. Questions? public class BankAccount { public void deposit(int cents){ balance += cents; } } public class BankAccount { public void deposit(Money money){ balance += money.CentsValue; } } Replace: int amount = 500; with: Money amount = new Money(500); account.deposit(amount); testDeposit(){ BankAccount account = new BankAccount(); int amount = 500; account.deposit(amount); assertEquals(500, account.getBalance()); testDeposit(){ BankAccount account = new BankAccount(); Money amount = new Money(500); account.deposit(amount); assertEquals(500, account.getBalance()); TestCareAssistant