A Metric Based Evaluation of Unit Tests as Specialized Clients in Refactoring

W. Basit, F. Lodhi, F. Ahmed, M. U. Bhatti


In the context of refactoring, a unit test significantly differs from an ordinary client. A unit test is the only safety net available to verify the impact of refactoring. In addition, tight coupling and stronger association with the refactored class are its key discriminating characteristics. Hence, any change in the code readily affects the behavior and quality of the test code. But if test code is adapted and refactored along the production code, its behavior shall be preserved and quality may improve. In this paper with the help of quality metrics, we establish the fact that unit test is a different type of client that needs “special“ handling in the context of refactoring. We demonstrate through most commonly used refactorings on an open source project that there is a need to enhance the existing refactoring support for Java to include the specific adaptation mechanism for unit tests that eradicates the effect of refactoring and also improves the internal structure of test code.

Full Text:



M. Fowler, K. Beck, J. Brant, W. Opdyke, and D. Roberts. Refactoring: Improving the Design of Existing Code. 1999

A. van Deursen and L. Moonen. The Video Store Revisited: Thoughts on Refactoring and Testing. In Proceedings of the 3rd International Conference on Extreme Programming and Agile Processes in Software Engineering (XP 2002), pp. 71-76, 2002

A. van Deursen, L. Moonen, A. van den Bergh and G. Kok. Refactoring Test Code. In Proceedings of the 2nd International Conference on Extreme Programming and Flexible Processes in Software Engineering (XP2001), pp. 92-95. 2001

S. Counsell , R. M. Hierons , R. Najjar , G. Loizou and Y. Hassoun, The Effectiveness of Refactoring, Based on a Compatibility Testing Taxonomy and a Dependency Graph, In Proceedings of the Testing: Academic & Industrial Conference on Practice And Research Techniques, p.181-192, August 29- 31, 2006

S. Counsell, S.Swift and R.M. Hierons, A Test Taxonomy Applied to the Mechanics of Java Refactorings, In Proceedings of SCSS (1), pp. 497--502 , 2007

S. Counsell, Is the need to follow chains a possible deterrent to certain refactorings and an inducement to others? In Proceedings of second International Conference on Research Challenges in Information Science, 2008

B. George and L. William, An Initial Investigation of Test Driven Development in Industry. In Proceedings of SAC ,2003

H. C. Jiau and J. C. Chen , Test code differencing for test-driven refactoring automation, ACM SIGSOFT Software Engineering Notes Volume 34 , Issue no 1, January, 2009

G. Meszaros and M. Fowler, xUnit Patterns: Refactoring Test Code, Addison-Wesley, 2007

B. Marick, Testing for Programmers, Lecture Notes available at: http://www.exampler.com/testingcom/writings/half-day-programmer.pdf

J. U. Pipka, Refactoring in a “test first”-world. In Proceedings of 3rd Int‟l Conference on eXtreme Programming and Flexible Processes in Software Engineering, 2002

J.Link and P. Frohlich, Unit Testing in Java: How Tests Drive The Code. Morgan Kaufmann ,2003

W. Basit, F. Lodhi and U. Bhatti, Extending Refactoring Guidelines to Perform Client and Test Code Adaptation, In Proceedings of XP 2010, pp. 1-13.

T. Mens and T. Tourwe´, “A Survey of Software Refactoring,” IEEE Trans. Software Eng., vol. 30, no. 2, pp. 126-139, Feb. 2004.

M. MirzaAghaei, F. Pastore and M. Pezz, Automatically repairing test cases for evolving method declarations. In Proceedings of ICSM 2010,pp. 1-5

B. Daniel, V. Jagannath, D. Dig, and D. Marinov. Reassert: Suggesting repairs for broken unit tests. Proceedings of the 24th IEEE/ACM international Conference on Automated Software Engineering. IEEE/ACM, 2009.

B. Daniel, T. Gvero, and D. Marinov, On test repair using symbolic Execution, In Proceedings of International Symposium on Software Testing and Analysis, 2010.

J. Henkel and A. Diwan. CatchUp!: Capturing and replaying refactorings to support API evolution.In Proceedings of ICSE‟05, pp. 274– 283.

A. Zaidman, B. V. Rompaey, S. Demeyer and A. van Deursen. Mining Software Repositories to Study Co-Evolution of Production and Test Code. In Proceedings of 1st International Conference on Software Testing (ICST'08), pp. 220-229, IEEE Computer Society, 2008

M. Streckenbach and G. Snelting. Refactoring class hierarchies with kaba. In Proceedings of the 19th annual ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications, pp. 315–330. ACM, 2004.

D. Dig, S. Negara, V. Mohindra, and R. Johnson. Reba: refactoring aware binary adaptation of evolving libraries. In Proceedings of the 30th international conference on Software engineering, pp, 441–450. ACM, 2008.

JUnit, At "http://www.junit.org”

Sun Microsystems, I. (2011). Netbeans ide. At http://www.netbeans.org/.

Eclipse.org (2011). Eclipse project. At http://www.eclipse.org.

Jet Brains, I. (2011). Intellij idea. At http://www.intellij.com/idea/.

Embarcadero Technologies, I. (2011). Jbuilder. At http://www.codegear.com/br/products/jbuilder.


F. Bannwart and P. Müller, Changing Programs Correctly: Refactoring with Specifications. Proceedings of FM pp, 492-507, 2007

E.M. Guerra and C.T. Fernandes, Refactoring Test Code Safely. In Proceedings of the International Conference on Software Engineering Advances , 2007

Different kinds of testing, At css.dzone.com/articles/different-kinds-testing accessed on 5th July, 2012

B. Daniel,D.Dig,K. Garcia and D. Marinov (2007). Automated testing of refactoring engines. In Foundations of Software Engineering, pages 185–194.

G. Soares, R. Gheyi, T. Massoni, M. Corn´elio, and D. Cavalcanti, “Generating unit tests for checking refactoring safety,” in SBLP, 2009, pp. 159–172

http://docs.codehaus.org/display/SONAR/Metri c+definitions

R.C.Martin (2002). Agile Software Development: Principles, Patterns and Practices. Pearson Education. ISBN 0-13- 597444-5.

S.Demeyer et al. 2005. The LAN-simulation: A Refactoring Teaching Example. In Proceedings of the Eighth International Workshop on Principles of Software Evolution (IWPSE '05). IEEE Computer Society, Washington, DC, USA, 123-134.

Cobertura, cobertura.sourceforge.net/

W. Basit, F. Lodhi and U. Bhatti,Evaluating Extended Refactoring Guidelines,To appear in Proceedings of QUORS 2012.

W. Basit and F. Lodhi , Preservation of Externally Observable Behavior after Pull Up 4Method Refactoring, In Proceedings of ICCIT 2012, pp. 309-314.

L.Kiran, F. Lodhi and W. Basit , Test Code Adaptation Plugin for Eclipse, In Proceedings of ICCIT 2012, pp. 297-302.

W. Basit, F. Lodhi and M.U. Bhatti,Unit Test: A specialized client in refactoring ,To appear in Proceedings of ICSOFT 2012. [41] Instability, http://codenforcer.com/instability.aspx accessed on: 5th July, 2012

Copyright (c) 2016 W. Basit, F. Lodhi, F. Ahmed, M. U. Bhatti

Powered By KICS