What Do the Asserts in a Unit Test Tell Us about Code Quality? A Study on Open Source and Industrial Projects

Unit tests and production code are intrinsically connected. A class that is easy to test usually presents desirable characteristics, such as low coupling and high cohesion. Thus, finding hard-to-test classes may help developers identify problematic code. Many different test feedbacks that warn developers about problematic code were already catalogued. In this paper, we argue that analyzing assert instructions in unit tests also aid in identifying and reasoning about potentially problematic pieces of code. We report an analysis conducted with both open source and industry projects relating assert instructions in a unit test with quality measures of the code being tested. We observed that when a production method has a unit test that uses the "assert" instruction in more than one object instance, it often exhibits higher cyclomatic complexity, number of lines of code, or higher number of method invocations. It means that developers should monitor the number of asserts in a unit test as it may indicate problems in the production code.

[1]  Jana Polgar,et al.  Object-Oriented Software Metrics , 2005, Encyclopedia of Information Science and Technology.

[2]  Robert V. Binder,et al.  Design for testability in object-oriented systems , 1994, CACM.

[3]  Mauricio Finavaro Aniche,et al.  How the Practice of TDD Influences Class Design in Object-Oriented Systems: Patterns of Unit Tests Feedback , 2012, 2012 26th Brazilian Symposium on Software Engineering.

[4]  Mohammad Alshayeb,et al.  Investigating the Effect of Refactoring on Software Testing Effort , 2009, 2009 16th Asia-Pacific Software Engineering Conference.

[5]  David S. Janzen,et al.  Test-driven development concepts, taxonomy, and future direction , 2005, Computer.

[6]  Arie van Deursen,et al.  An empirical study into class testability , 2006, J. Syst. Softw..

[7]  David S. Janzen,et al.  On the Influence of Test-Driven Development on Software Design , 2006, 19th Conference on Software Engineering Education & Training (CSEET'06).

[8]  Kent L. Beck,et al.  Aim, Fire , 2001, IEEE Softw..

[9]  David Janzen Software architecture improvement through test-driven development , 2005, OOPSLA '05.

[10]  Anas N. Al-Rabadi,et al.  A comparison of modified reconstructability analysis and Ashenhurst‐Curtis decomposition of Boolean functions , 2004 .

[11]  Mark Lorenz,et al.  Object-oriented software metrics - a practical guide , 1994 .

[12]  Charles Ashbacher Growing Object-Oriented Software, Guided by Tests , 2010, J. Object Technol..

[13]  Angélica Caro,et al.  A Probabilistic Approach to Web Portal's Data Quality Evaluation , 2007 .

[14]  Stephen L. Burbeck,et al.  Applications programming in smalltalk-80: how to use model-view-controller (mvc) , 1987 .

[15]  Kent L. Beck,et al.  Test-driven Development - by example , 2002, The Addison-Wesley signature series.

[16]  Brian Henderson-Sellers,et al.  Object-oriented metrics: measures of complexity , 1995 .

[17]  Arie van Deursen,et al.  Refactoring test code , 2001 .

[18]  Dewayne E. Perry,et al.  Metrics and laws of software evolution-the nineties view , 1997, Proceedings Fourth International Software Metrics Symposium.

[19]  Kent L. Beck,et al.  Extreme programming explained - embrace change , 1990 .

[20]  Leon Moonen,et al.  Java quality assurance by detecting code smells , 2002, Ninth Working Conference on Reverse Engineering, 2002. Proceedings..

[21]  Joost Visser,et al.  A Practical Model for Measuring Maintainability , 2007, 6th International Conference on the Quality of Information and Communications Technology (QUATIC 2007).

[22]  Sallie M. Henry,et al.  Object-oriented metrics that predict maintainability , 1993, J. Syst. Softw..

[23]  Boby George,et al.  An initial investigation of test driven development in industry , 2003, SAC '03.

[24]  John D. McGregor,et al.  A Practical Guide to Testing Object-Oriented Software , 2001, Addison Wesley object technology series.

[25]  Chris F. Kemerer,et al.  A Metrics Suite for Object Oriented Design , 2015, IEEE Trans. Software Eng..

[26]  Jeff Langr Evolution of Test and Code Via Test-First Design , 2001 .

[27]  Andrew Hunt,et al.  Pragmatic Unit Testing in Java with JUnit , 2003 .