ABSTRACT
Unit testing focuses on verifying the functions of individual units of a software system. It is challenging due to the high inter-dependencies among software units. Developers address this by mocking-replacing the dependency by a "faked" object. Despite the existence of powerful, dedicated mocking frameworks, developers often turn to a "hand-rolled" approach-inheritance. That is, they create a subclass of the dependent class and mock its behavior through method overriding. However, this requires tedious implementation and compromises the design quality of unit tests. This work contributes a fully automated refactoring framework to identify and replace the usage of inheritance by using Mockito-a well received mocking framework. Our approach is built upon the empirical experience from five open source projects that use inheritance for mocking. We evaluate our approach on four other projects. Results show that our framework is efficient, generally applicable to new datasets, mostly preserves test case behaviors in detecting defects (in the form of mutants), and decouples test code from production code. The qualitative evaluation by experienced developers suggests that the auto-refactoring solutions generated by our framework improve the quality of the unit test cases in various aspects, such as making test conditions more explicit, as well as improved cohesion, readability, understandability, and maintainability with test cases.
- [n.d.]. https://easymock.org/Google Scholar
- [n.d.]. https://site.mockito.org/Google Scholar
- [n.d.]. https://powermock.github.io/Google Scholar
- [n.d.]. https://junit.org/junit5/Google Scholar
- [n.d.]. https://wiki.python.org/moin/PyUnitGoogle Scholar
- [n.d.]. https://dubbo.apache.org/Google Scholar
- [n.d.]. https://druid.apache.org/Google Scholar
- [n.d.]. https://accumulo.apache.org/Google Scholar
- [n.d.]. https://cayenne.apache.org/Google Scholar
- [n.d.]. https://cloudstack.apache.org/Google Scholar
- [n.d.]. https://javadoc.io/static/org.mockito/mockito-core/3.1.0/org/mockito/MockSettings.html#extraInterfaces-java.lang.Class...-Google Scholar
- [n.d.]. https://github.com/mockito/mockito/wiki/FAQ#what-are-the-limitations-of-mockitoGoogle Scholar
- [n.d.]. https://github.com/FasterXML/jackson-annotations/wiki/Jackson-AnnotationsGoogle Scholar
- [n.d.]. https://projects.eclipse.org/projects/eclipse.jdtGoogle Scholar
- [n.d.]. https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/stubbing/OngoingStubbing.html#thenAnswer-org.mockito.stubbing.Answer-Google Scholar
- [n.d.]. https://jackrabbit.apache.org/jcr/index.htmlGoogle Scholar
- [n.d.]. https://logging.apache.org/log4j/Google Scholar
- [n.d.]. https://qpid.apache.org/Google Scholar
- [n.d.]. https://pitest.org/Google Scholar
- [n.d.]. https://pitest.org/quickstart/mutators/Google Scholar
- [n.d.]. https://aws.amazon.com/lightsail/Google Scholar
- [n.d.]. https://doi.org/10.5281/zenodo.5111183 Google ScholarDigital Library
- Mesfin Abebe and Cheol-Jung Yoo. 2014. Trends, opportunities and challenges of software refactoring: A systematic literature review. international Journal of software engineering and its Applications, 8, 6 (2014), 299–318.Google Scholar
- Paul Ammann and Jeff Offutt. 2016. Introduction to software testing. Cambridge University Press. https://doi.org/10.1017/9781316771273 Google ScholarCross Ref
- Magdalena Balazinska, Ettore Merlo, Michel Dagenais, Bruno Lague, and Kostas Kontogiannis. 2000. Advanced clone-analysis to support object-oriented system refactoring. In Proceedings Seventh Working Conference on Reverse Engineering. 98–107. https://doi.org/10.1109/WCRE.2000.891457 Google ScholarCross Ref
- Abdulrahman Ahmed Bobakr Baqais and Mohammad Alshayeb. 2020. Automatic software refactoring: a systematic literature review. Software Quality Journal, 28, 2 (2020), 459–502. https://doi.org/10.1007/s11219-019-09477-y Google ScholarDigital Library
- Gabriele Bavota, Andrea De Lucia, Andrian Marcus, and Rocco Oliveto. 2010. A two-step technique for extract class refactoring. In Proceedings of the IEEE/ACM international conference on Automated software engineering. 151–154. https://doi.org/10.1145/1858996.1859024 Google ScholarDigital Library
- Gabriele Bavota, Malcom Gethers, Rocco Oliveto, Denys Poshyvanyk, and Andrea de Lucia. 2014. Improving software modularization via automated analysis of latent topics and dependencies. ACM Transactions on Software Engineering and Methodology (TOSEM), 23, 1 (2014), 1–33. https://doi.org/10.1145/2559935 Google ScholarDigital Library
- Gabriele Bavota, Rocco Oliveto, Andrea De Lucia, Giuliano Antoniol, and Yann-Gaël Guéhéneuc. 2010. Playing with refactoring: Identifying extract class opportunities through game theory. In 2010 IEEE International Conference on Software Maintenance. 1–5. https://doi.org/10.1109/ICSM.2010.5609739 Google ScholarDigital Library
- Gabriele Bavota, Abdallah Qusef, Rocco Oliveto, Andrea De Lucia, and David Binkley. 2012. An empirical analysis of the distribution of unit test smells and their impact on software maintenance. In 2012 28th IEEE International Conference on Software Maintenance (ICSM). 56–65. https://doi.org/10.1109/ICSM.2012.6405253 Google ScholarDigital Library
- Gabriele Bavota, Abdallah Qusef, Rocco Oliveto, Andrea De Lucia, and Dave Binkley. 2015. Are test smells really harmful? an empirical study. Empirical Software Engineering, 20, 4 (2015), 1052–1094. https://doi.org/10.1007/s10664-014-9313-0 Google ScholarDigital Library
- Kent Beck. 2003. Test-driven development: by example. Addison-Wesley Professional.Google ScholarDigital Library
- Moritz Beller, Georgios Gousios, Annibale Panichella, Sebastian Proksch, Sven Amann, and Andy Zaidman. 2017. Developer testing in the ide: Patterns, beliefs, and behavior. IEEE Transactions on Software Engineering, 45, 3 (2017), 261–284. https://doi.org/10.1109/TSE.2017.2776152 Google ScholarDigital Library
- Moritz Beller, Georgios Gousios, Annibale Panichella, and Andy Zaidman. 2015. When, how, and why developers (do not) test in their IDEs. In Proceedings of the 2015 10th Joint Meeting on Foundations of Software Engineering. 179–190. https://doi.org/10.1145/2786805.2786843 Google ScholarDigital Library
- Stefan Berner, Roland Weber, and Rudolf K Keller. 2005. Observations and lessons learned from automated testing. In Proceedings of the 27th international conference on Software engineering. 571–579. https://doi.org/10.1109/ICSE.2005.1553603 Google ScholarCross Ref
- Antonia Bertolino. 2007. Software testing research: Achievements, challenges, dreams. In Future of Software Engineering (FOSE’07). 85–103. https://doi.org/10.1109/FOSE.2007.25 Google ScholarDigital Library
- Alexander Chatzigeorgiou, Spiros Xanthos, and George Stephanides. 2004. Evaluating object-oriented designs with link analysis. In Proceedings. 26th International Conference on Software Engineering. 656–665. https://doi.org/10.1109/ICSE.2004.1317487 Google ScholarCross Ref
- Don Coleman, Dan Ash, Bruce Lowther, and Paul Oman. 1994. Using metrics to evaluate software system maintainability. Computer, 27, 8 (1994), 44–49. https://doi.org/10.1109/2.303623 Google ScholarDigital Library
- Ermira Daka and Gordon Fraser. 2014. A survey on unit testing practices and problems. In 2014 IEEE 25th International Symposium on Software Reliability Engineering. 201–211. https://doi.org/10.1109/ISSRE.2014.11 Google ScholarDigital Library
- Karim O Elish and Mohammad Alshayeb. 2009. Investigating the effect of refactoring on software testing effort. In 2009 16th Asia-Pacific Software Engineering Conference. 29–34. https://doi.org/10.1109/APSEC.2009.14 Google ScholarDigital Library
- Marios Fokaefs, Nikolaos Tsantalis, Eleni Stroulia, and Alexander Chatzigeorgiou. 2012. Identification and application of extract class refactorings in object-oriented systems. Journal of Systems and Software, 85, 10 (2012), 2241–2260. https://doi.org/10.1016/j.jss.2012.04.013 Google ScholarDigital Library
- Martin Fowler. 2018. Refactoring: improving the design of existing code. Addison-Wesley Professional. https://doi.org/10.1007/3-540-45672-4_31 Google ScholarCross Ref
- Steve Freeman, Tim Mackinnon, Nat Pryce, and Joe Walnes. 2004. Mock roles, not objects. In Companion to the 19th annual ACM SIGPLAN conference on Object-oriented programming systems, languages, and applications. 236–246. https://doi.org/10.1145/1028664.1028765 Google ScholarDigital Library
- George Ganea, Ioana Verebi, and Radu Marinescu. 2017. Continuous quality assessment with inCode. Science of Computer Programming, 134 (2017), 19–36. https://doi.org/10.1016/j.scico.2015.02.007 Google ScholarDigital Library
- Vahid Garousi, Baris Kucuk, and Michael Felderer. 2018. What we know about smells in software test code. IEEE Software, 36, 3 (2018), 61–73. https://doi.org/10.1109/MS.2018.2875843 Google ScholarCross Ref
- Java Code Geeks. [n.d.]. Mockito Programming Cookbook. https://www.javacodegeeks.com/wp-content/uploads/2016/09/Mockito-Programming-Cookbook.pdfGoogle Scholar
- Michaela Greiler, Arie Van Deursen, and Margaret-Anne Storey. 2013. Automated detection of test fixture strategies and smells. In 2013 IEEE Sixth International Conference on Software Testing, Verification and Validation. 322–331. https://doi.org/10.1109/ICST.2013.45 Google ScholarDigital Library
- Jeff Grigg. 2012. http://wiki.c2.com/?ArrangeActAssert/Google Scholar
- Tor Guimaraes. 1983. Managing application program maintenance expenditures. Commun. ACM, 26, 10 (1983), 739–746. https://doi.org/10.1145/358413.358421 Google ScholarDigital Library
- Keisuke Hotta, Yoshiki Higo, and Shinji Kusumoto. 2012. Identifying, tailoring, and suggesting form template method refactoring opportunities with program dependence graph. In 2012 16th European Conference on Software Maintenance and Reengineering. 53–62. https://doi.org/10.1109/CSMR.2012.16 Google ScholarDigital Library
- Clemente Izurieta and James M Bieman. 2007. How software designs decay: A pilot study of pattern evolution. In First International Symposium on Empirical Software Engineering and Measurement (ESEM 2007). 449–451. https://doi.org/10.1109/ESEM.2007.55 Google ScholarDigital Library
- Yoshio Kataoka, Michael D Ernst, William G Griswold, and David Notkin. 2001. Automated support for program refactoring using invariants. In Proceedings IEEE International Conference on Software Maintenance. ICSM 2001. 736–743. https://doi.org/10.1109/ICSM.2001.972794 Google ScholarDigital Library
- Chris F. Kemerer and Sandra Slaughter. 1999. An empirical approach to studying software evolution. IEEE transactions on software engineering, 25, 4 (1999), 493–509. https://doi.org/10.1109/32.799945 Google ScholarDigital Library
- Miryung Kim, Thomas Zimmermann, and Nachiappan Nagappan. 2012. A field study of refactoring challenges and benefits. In Proceedings of the ACM SIGSOFT 20th International Symposium on the Foundations of Software Engineering. 1–11. https://doi.org/10.1145/2393596.2393655 Google ScholarDigital Library
- Negar Koochakzadeh and Vahid Garousi. 2010. A tester-assisted methodology for test redundancy detection. Advances in Software Engineering, 2010 (2010), https://doi.org/10.1155/2010/932686 Google ScholarDigital Library
- Madhuri R Marri, Tao Xie, Nikolai Tillmann, Jonathan De Halleux, and Wolfram Schulte. 2009. An empirical study of testing file-system-dependent software with mock objects. In 2009 ICSE Workshop on Automation of Software Test. 149–153. https://doi.org/10.1007/s10664-018-9663-0 Google ScholarDigital Library
- Philip Mayer and Andreas Schroeder. 2014. Automated multi-language artifact binding and rename refactoring between Java and DSLs used by Java frameworks. In European Conference on Object-Oriented Programming. 437–462. https://doi.org/10.1007/978-3-662-44202-9_18 Google ScholarDigital Library
- Davood Mazinanian, Nikolaos Tsantalis, Raphael Stein, and Zackary Valenta. 2016. JDeodorant: clone refactoring. In Proceedings of the 38th international conference on software engineering companion. 613–616. https://doi.org/10.1145/2889160.2889168 Google ScholarDigital Library
- Tom Mens and Tom Tourwé. 2004. A survey of software refactoring. IEEE Transactions on software engineering, 30, 2 (2004), 126–139. https://doi.org/10.1109/TSE.2004.1265817 Google ScholarDigital Library
- Tom Mens, Michel Wermelinger, Stéphane Ducasse, Serge Demeyer, Robert Hirschfeld, and Mehdi Jazayeri. 2005. Challenges in software evolution. In Eighth International Workshop on Principles of Software Evolution (IWPSE’05). 13–22. https://doi.org/10.1109/IWPSE.2005.7 Google ScholarDigital Library
- Gerard Meszaros. 2007. xUnit test patterns: Refactoring test code. Pearson Education. https://doi.org/10.1145/1869542.1869622 Google ScholarDigital Library
- Mohamed Wiem Mkaouer, Marouane Kessentini, Slim Bechikh, Kalyanmoy Deb, and Mel Ó Cinnéide. 2014. Recommendation system for software refactoring using innovization and interactive dynamic optimization. In Proceedings of the 29th ACM/IEEE international conference on Automated software engineering. 331–336. https://doi.org/10.1145/2642937.2642965 Google ScholarDigital Library
- Shaikh Mostafa and Xiaoyin Wang. 2014. An empirical study on the usage of mocking frameworks in software testing. In 2014 14th international conference on quality software. 127–132. https://doi.org/10.1109/QSIC.2014.19 Google ScholarDigital Library
- Glenford J Myers, Tom Badgett, Todd M Thomas, and Corey Sandler. 2004. The art of software testing. 2, Wiley Online Library. https://doi.org/10.1002/9781119202486 Google ScholarCross Ref
- Jagadeesh Nandigam, Venkat N Gudivada, Abdelwahab Hamou-Lhadj, and Yonglei Tao. 2009. Interface-based object-oriented design with mock objects. In 2009 Sixth International Conference on Information Technology: New Generations. 713–718. https://doi.org/10.1109/ITNG.2009.268 Google ScholarDigital Library
- William F Opdyke. 1992. Refactoring object-oriented frameworks.Google Scholar
- Fabio Palomba, Dario Di Nucci, Annibale Panichella, Rocco Oliveto, and Andrea De Lucia. 2016. On the diffusion of test smells in automatically generated test code: An empirical study. In 2016 IEEE/ACM 9th International Workshop on Search-Based Software Testing (SBST). 5–14. https://doi.org/10.1145/2897010.2897016 Google ScholarDigital Library
- Gustavo Pereira and Andre Hora. 2020. Assessing Mock Classes: An Empirical Study. In 2020 IEEE International Conference on Software Maintenance and Evolution (ICSME). 453–463. https://doi.org/10.1109/ICSME46990.2020.00050 Google ScholarCross Ref
- Stefan Reichhart, Tudor Gîrba, and Stéphane Ducasse. 2007. Rule-based Assessment of Test Quality.. J. Object Technol., 6, 9 (2007), 231–251.Google ScholarCross Ref
- Per Runeson. 2006. A survey of unit testing practices. IEEE software, 23, 4 (2006), 22–29. https://doi.org/10.1109/MS.2006.91 Google ScholarDigital Library
- Railana Santana, Luana Martins, Larissa Rocha, Tássio Virgínio, Adriana Cruz, Heitor Costa, and Ivan Machado. 2020. RAIDE: a tool for Assertion Roulette and Duplicate Assert identification and refactoring. In Proceedings of the 34th Brazilian Symposium on Software Engineering. 374–379. https://doi.org/10.1145/3422392.3422510 Google ScholarDigital Library
- Sandro Schulze and Martin Kuhlemann. 2009. Advanced analysis for code clone removal. In Proceedings des Workshops der GI-Fachgruppe Software Reengineering (SRE), erschienen in den GI Softwaretechnik-Trends 29 (2). 10–12.Google Scholar
- Davide Spadini, Maurício Aniche, Magiel Bruntink, and Alberto Bacchelli. 2017. To mock or not to mock? An empirical study on mocking practices. In 2017 IEEE/ACM 14th International Conference on Mining Software Repositories (MSR). 402–412. https://doi.org/10.1109/MSR.2017.61 Google ScholarDigital Library
- Davide Spadini, Maurício Aniche, Magiel Bruntink, and Alberto Bacchelli. 2019. Mock objects for testing java systems. Empirical Software Engineering, 24, 3 (2019), 1461–1498. https://doi.org/10.1007/s10664-018-9663-0 Google ScholarDigital Library
- Davide Spadini, Fabio Palomba, Andy Zaidman, Magiel Bruntink, and Alberto Bacchelli. 2018. On the relation of test smells to software code quality. In 2018 IEEE International Conference on Software Maintenance and Evolution (ICSME). 1–12. https://doi.org/10.1109/ICSME.2018.00010 Google ScholarCross Ref
- Gábor Szoke, Csaba Nagy, Rudolf Ferenc, and Tibor Gyimóthy. 2016. Designing and developing automated refactoring transformations: An experience report. In 2016 IEEE 23rd International Conference on Software Analysis, Evolution, and Reengineering (SANER). 1, 693–697. https://doi.org/10.1109/SANER.2016.17 Google ScholarCross Ref
- Robert Tairas and Jeff Gray. 2009. Get to know your clones with CeDAR. In Proceedings of the 24th ACM SIGPLAN conference companion on Object oriented programming systems languages and applications. 817–818. https://doi.org/10.1145/1639950.1640030 Google ScholarDigital Library
- Robert Tairas and Jeff Gray. 2012. Increasing clone maintenance support by unifying clone detection and refactoring activities. Information and Software Technology, 54, 12 (2012), 1297–1307. https://doi.org/10.1016/j.infsof.2012.06.011 Google ScholarDigital Library
- Nikolaos Tsantalis and Alexander Chatzigeorgiou. 2010. Identification of refactoring opportunities introducing polymorphism. Journal of Systems and Software, 83, 3 (2010), 391–404. https://doi.org/10.1016/j.jss.2009.09.017 Google ScholarDigital Library
- Qiang Tu. 2000. Evolution in open source software: A case study. In Proceedings 2000 International Conference on Software Maintenance. 131–142. https://doi.org/10.1109/ICSM.2000.883030 Google ScholarCross Ref
- Michele Tufano, Fabio Palomba, Gabriele Bavota, Massimiliano Di Penta, Rocco Oliveto, Andrea De Lucia, and Denys Poshyvanyk. 2016. An empirical investigation into the nature of test smells. In Proceedings of the 31st IEEE/ACM International Conference on Automated Software Engineering. 4–15. https://doi.org/10.1145/2970276.2970340 Google ScholarDigital Library
- Arie Van Deursen, Leon Moonen, Alex Van Den Bergh, and Gerard Kok. 2001. Refactoring test code. In Proceedings of the 2nd international conference on extreme programming and flexible processes in software engineering (XP2001). 92–95.Google Scholar
- B. Van Rompaey, B. Du Bois, S. Demeyer, and M. Rieger. 2007. On The Detection of Test Smells: A Metrics-Based Approach for General Fixture and Eager Test. IEEE Transactions on Software Engineering, 33, 12 (2007), 800–817. https://doi.org/10.1109/TSE.2007.70745 Google ScholarDigital Library
- Frens Vonken and Andy Zaidman. 2012. Refactoring with unit testing: A match made in heaven? In 2012 19th Working Conference on Reverse Engineering. 29–38. https://doi.org/10.1109/WCRE.2012.13 Google ScholarDigital Library
- William C Wake. 2004. Refactoring workbook. Addison-Wesley Professional.Google Scholar
- Andy Zaidman, Bart Van Rompaey, Arie van Deursen, and Serge Demeyer. 2011. Studying the co-evolution of production and test code in open source and industrial developer test processes through repository mining. Empirical Software Engineering, 16, 3 (2011), 325–364. https://doi.org/10.1007/s10664-010-9143-7 Google ScholarDigital Library
- Marcelo Serrano Zanetti, Claudio Juan Tessone, Ingo Scholtes, and Frank Schweitzer. 2014. Automated software remodularization based on move refactoring: a complex systems approach. In Proceedings of the 13th international conference on Modularity. 73–84. https://doi.org/10.1145/2577080.2577097 Google ScholarDigital Library
- Liming Zhao and Jane Huffman Hayes. 2011. Rank-based refactoring decision support: two studies. Innovations in Systems and Software Engineering, 7, 3 (2011), 171–189. https://doi.org/10.1007/s11334-011-0154-3 Google ScholarDigital Library
Index Terms
- An automatic refactoring framework for replacing test-production inheritance by mocking mechanism
Recommendations
A Static Approach to Prioritizing JUnit Test Cases
Test case prioritization is used in regression testing to schedule the execution order of test cases so as to expose faults earlier in testing. Over the past few years, many test case prioritization techniques have been proposed in the literature. Most ...
Improving Fault Detection Capability by Selectively Retaining Test Cases during Test Suite Reduction
Software testing is a critical part of software development. As new test cases are generated over time due to software modifications, test suite sizes may grow significantly. Because of time and resource constraints for testing, test suite minimization ...
Prioritizing random combinatorial test suites
SAC '17: Proceedings of the Symposium on Applied ComputingThe behaviour of a system under test can be influenced by several factors, such as system configurations, user inputs, and so on. It has also been observed that many failures are caused by only a small number of factors. Combinatorial testing aims at ...
Comments