E. Soares, M. Ribeiro, R. Gheyi, G. Amaral and A. Santos, “Refactoring Test Smells With JUnit 5: Why Should Developers Keep Up-to-Date?” in IEEE Transactions on Software Engineering, vol. 49, no. 3, pp. 1152-1170, 1 March 2023
Test smells are symptoms in the test code that indicate possible design or implementation problems. Previous research demonstrated their harmfulness and the developers’ acknowledgment of test smells’ effects, prevention, and refactoring strategies. Test automation frameworks are constantly evolving, and the JUnit, one of the most used ones for Java projects, has its version 5 available since late 2017. However, we do not know the extent to which developers use the newly introduced features and whether such features indeed help refactor existing test code to remove test smells. This article conducts a mixed-method study investigation to minimize these knowledge gaps. Our study consists of three parts. First, we evaluate the usage of this framework and its features by analyzing the source code of 485 popular Java open-source projects on GitHub that use JUnit. We found that 15.9% of these projects use the JUnit 5 library. We also found that, from 17 new features detected in use, only 3 (i.e., 17.6%) are responsible for more than 70% of usages, limiting optimized propositions to test code creation and maintenance. Second, after identifying features in the JUnit 5 framework that could be considered to test smells removal and prevention, we use these features to propose novel refactorings. In particular, we present refactorings based on 7 introduced JUnit 5 features that help to remove 13 test smells, such as Assertion Roulette, Test Code Duplication, and Conditional Test Logic. Third, to evaluate our refactorings with the opinions of experienced developers, we (i) survey 212 developers for their preferences and comments about our refactorings, corroborating the benefits of our proposals and raising community feedback on JUnit 5 features, and (ii) we refactor actual test code from popular GitHub Java projects and submit 38 Pull Requests, reaching a 94% acceptance rate among respondents. As implications of our study, we alert the software testing community (i.e., practitioners and researchers) to the need to study the JUnit 5 features to effectively remove and prevent test smells. To better assist this process, we give directions on how test smells can be refactored using such features.
Elvys Soares, Centro de Informática, Universidade Federal de Pernambuco (UFPE), Recife, PE, Brazil
Márcio Ribeiro, Instituto de Computação, Universidade Federal de Alagoas (UFAL), Maceió, Brazil
Rohit Gheyi, Departamento de Sistemas e Computação, Universidade Federal de Campina Grande (UFCG), Campina Grande, PB, Brazil
Guilherme Amaral, Instituto de Computação, Universidade Federal de Alagoas (UFAL), Maceió, Brazil
André Santos, Centro de Informática, Universidade Federal de Pernambuco (UFPE), Recife, PE, Brazil