Generating Unit Tests for Checking Refactoring Safety



Similar documents
Colligens: A Tool to Support the Development of Preprocessor-based Software Product Lines in C

Description of Class Mutation Mutation Operators for Java

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Software Quality Exercise 2

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard

Towards Software Configuration Management for Test-Driven Development

Part I. Multiple Choice Questions (2 points each):

Unit Testing. and. JUnit

Jidoka in Software Development

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

Basics of Java Programming Input and the Scanner class

Java with Eclipse: Setup & Getting Started

System requirements for ICS Skills ATS

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

More on Objects and Classes

Code Qualities and Coding Practices

Author: Sascha Wolski Sebastian Hennebrueder Tutorials for Struts, EJB, xdoclet and eclipse.

Test-Driven Development

Editors Comparison (NetBeans IDE, Eclipse, IntelliJ IDEA)

The Rules 1. One level of indentation per method 2. Don t use the ELSE keyword 3. Wrap all primitives and Strings

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Introduction to Computer Programming, Spring Term 2014 Practice Assignment 3 Discussion

An Automatic Reversible Transformation from Composite to Visitor in Java

AP Computer Science Static Methods, Strings, User Input

Install Java Development Kit (JDK) 1.8

AP Computer Science Java Subset

Static vs. Dynamic. Lecture 10: Static Semantics Overview 1. Typical Semantic Errors: Java, C++ Typical Tasks of the Semantic Analyzer

Using Continuous Code Change Analysis to Understand the Practice of Refactoring

Lab 5: Bank Account. Defining objects & classes

CS 106 Introduction to Computer Science I

Meister Going Beyond Maven

Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Unit Testing and JUnit

Pattern Insight Clone Detection

This explanations are for absolute beginners. Skilled programmers should (and probably will) use more effective approach.

Building Java Programs

Building Java Programs

Java CPD (I) Frans Coenen Department of Computer Science

Dart a modern web language

Chapter 2 Elementary Programming

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

Chapter 3. Input and output. 3.1 The System class

CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards

Sample CSE8A midterm Multiple Choice (circle one)

Pluggable Type Systems. Gilad Bracha

Using Files as Input/Output in Java 5.0 Applications

Parameter Passing. Standard mechanisms. Call by value-result Call by name, result

Continuous integration for databases using

Introduction to Programming

Computer Programming I

SE 360 Advances in Software Development Object Oriented Development in Java. Polymorphism. Dr. Senem Kumova Metin

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

How do APIs evolve? A story of refactoring

Java SE 7 Programming

Java (12 Weeks) Introduction to Java Programming Language

CS 2112 Lab: Version Control

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

CS 1133, LAB 2: FUNCTIONS AND TESTING

Java SE 7 Programming

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

Data Structures Lecture 1

Table of Contents. LESSON: The JUnit Test Tool...1. Subjects...2. Testing What JUnit Provides...4. JUnit Concepts...5

Java: overview by example

Java EE 6 development with Eclipse, Netbeans, IntelliJ and GlassFish. Ludovic Champenois Oracle Corporation

Programming Languages

Tech Notes. Corporate Headquarters EMEA Headquarters Asia-Pacific Headquarters 100 California Street, 12th Floor San Francisco, California 94111

Java Interview Questions and Answers

Refactoring (in) Eclipse

Tutorial 7 Unit Test and Web service deployment

Getting started with API testing

Java Programming Language

CS 209 Programming in Java #1

Concordion. Concordion. Tomo Popovic, tp0x45 [at] gmail.com

Continuous integration for databases using Redgate tools

Project 4 DB A Simple database program

1 bool operator==(complex a, Complex b) { 2 return a.real()==b.real() 3 && a.imag()==b.imag(); 4 } 1 bool Complex::operator==(Complex b) {

Effective unit testing with JUnit

The Effectiveness of Automated Static Analysis Tools for Fault Detection and Refactoring Prediction

Android Introduction. Hello Mihail L. Sichitiu 1

Test Driven Development

STORM. Simulation TOol for Real-time Multiprocessor scheduling. Designer Guide V3.3.1 September 2009

City of Berkeley. Accounts Payable Audit

Rational Team Concert. Guido Salvaneschi Dipartimento di Elettronica e Informazione Politecnico di Milano salvaneschi@elet.polimi.

Transcription:

Generating Unit Tests for Checking Refactoring Safety Gustavo Soares, Rohit Gheyi, Tiago Massoni Márcio Cornélio, Diego Cavalcanti UFCG / UPE {gsoares, rohit, massoni, diegot}@dsc.ufcg.edu.br marcio@dsc.upe.br 1

Context Refactoring must preserve the external behavior of the code It can be manual, which is error-prone and time consuming Example: Rename Class Name Conflicts Where is it used? 2

Refactoring Tools In order to help the refactoring process, several tools automate a number of refactorings Eclipse Netbeans JBuilder IntelliJ 3

Motivating Example Incorrect Handling of Type Accesses Source A int k() B int k() Push Down refactoring Target A int k() B int k() Where int m() { return super.k(); } int m() Tools C C int test() int m() int test() 4

Problem Refactoring tools may perform erroneous transformations, changing the behavior of the code 5

Refactoring Conditions Source Target R I R Refactoring R Refactoring Conditions I Implemented Conditions 6

Behavioral Change Errors Developers rely on tests to attest that behavior is preserved Many times, it goes undetected Situations The software may not has a test suite The test suite is often refactored as well, which may lead to bugs 7

Goal A technique to increase the chances to identify refactoring errors. We focus on behavioral change errors. 8

Technique Static Analysis Methods Source program 1 5? Target program 3 Test Suite 4 2 Unit Test Generator Refactoring Change 9

Example Push Down method Source 1 Target A int A.k() int B.k() int C.test() A int k() int k() B int k() int m() C int test() 2 Randoop 3 4 500 tests 500/500 400/500 5 The transformation is not safe! B int k() C int test() int m() 10

Evaluation The technique was evaluated against 16 wrong transformations intended to be refactorings All transformations were applied by the best Java refactoring tools and that do not preserve the behavior of the code Eclipse Netbeans JBuilder IntelliJ 11

Transformations Characteristics Small programs Up to 4 classes Inheritance and Inner classes Up to 4 methods override and overload 12

Evaluated Refactorings Refactoring Rename (class, variable, method) Encapsulate field Extract (method, class) Push Down method Pull up method 3 out of 5 of those refactorings are in top 4 of most used refactorings for Java developers on Eclipse 13

Evaluation Results Our technique detected problems in all 16 transformations except 1. 14

Example Rename Variable Shadow Static Import Source Circle double roundpi = 3.2 double r = 1 double area() double test() 3.14 Rename refactoring Tools 3.2 Target Circle double PI = 3.2 double r = 1 double area() double test() Where import Math.PI 100/100 98/100 100 tests double area() { return PI * r * r; } 15

Generated Unit Test public void test2() { Circle var0 = new Circle(); double var1 = var0.test(); asserttrue(var1 == 3.14); } 16

Discussion It is too difficult to correctly propose all conditions in an ad-hoc way Another approach is to verify the refactoring with respect to a formal semantic This is indeed a challenge R I R R Refactoring Conditions I Implemented Conditions 17

Conclusion We presented a technique for checking refactoring safety. In specially, helping the developer to identify behavioral changes errors. 18

Limitations Behavior Only Expressed in Output A void k() B void k() void m() void k() { System.out.print( 23 ); } void k() { System.out.print( 42 ); } C void test() The current technique does not generate a test that detects this type of change 19

Generating Unit Tests for Checking Refactoring Safety Gustavo Soares, Rohit Gheyi, Tiago Massoni Márcio Cornélio, Diego Cavalcanti UFCG / UPE {gsoares, rohit, massoni, diegot}@dsc.ufcg.edu.br marcio@dsc.upe.br 20