Roslan, M.F., Rojas, J.M. and McMinn, P. orcid.org/0000-0001-9137-7433
(2024)
Private—Keep out? Understanding how developers account for code visibility in unit testing.
In:
2024 IEEE International Conference on Software Maintenance and Evolution (ICSME).
40th International Conference on Software Maintenance and Evolution (ICSME 2024), 06-11 Oct 2024, Flagstaff, AZ, USA.
Institute of Electrical and Electronics Engineers (IEEE)
, pp. 312-324.
ISBN 979-8-3503-9568-6
Abstract
Regression test maintenance costs can be reduced by striving to write tests that will require as few changes as possible in the future. Writing unit tests against behavior, as opposed to implementation, is one way to try to achieve this, because as long as the public API remains constant, units can be safely refactored without the need to also change the tests. However, in a study on 4,801 open-source Java projects reported in this paper, we found that 28% of projects contradict this advice, with tests that side-step the public API by directly calling non-public methods. We investigated why developers do not solely test public APIs—potentially increasing future test maintenance costs—by surveying 73 developers and conducting a systematic review of 60 StackOverflow posts dating from 2008–2023. Through numerical and thematic analyses, we uncover several findings, including (1) developers are disunited on whether to test only through public APIs or not; (2) those in favor of only testing through the public API tend to be more experienced and believe the need or desire to break with this is borne out of poor software design; while (3) those that test non-public methods directly are concerned about untested code complexity and overly intricate tests. Our findings provide multiple implications for future work, including automated developer support in the form of automated non-public method sequence replacement, and automated refactoring of production code using problematic \public API-avoiding tests.
Metadata
Item Type: | Proceedings Paper |
---|---|
Authors/Creators: |
|
Copyright, Publisher and Additional Information: | © 2024 The Author(s). Except as otherwise noted, this author-accepted version of a paper published in 2024 IEEE International Conference on Software Maintenance and Evolution (ICSME) is made available via the University of Sheffield Research Publications and Copyright Policy under the terms of the Creative Commons Attribution 4.0 International License (CC-BY 4.0), which permits unrestricted use, distribution and reproduction in any medium, provided the original work is properly cited. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/ |
Keywords: | Surveys; Java; Software maintenance; Codes; Costs; Software design; Statistical analysis; Writing; Maintenance; Testing; Test Maintenance; Test Smells; Unit Testing; Access Modifiers; Developer Survey; Unit Testing Practices |
Dates: |
|
Institution: | The University of Sheffield |
Academic Units: | The University of Sheffield > Faculty of Engineering (Sheffield) > Department of Computer Science (Sheffield) |
Funding Information: | Funder Grant number ENGINEERING AND PHYSICAL SCIENCE RESEARCH COUNCIL EP/X024539/1 |
Depositing User: | Symplectic Sheffield |
Date Deposited: | 06 Sep 2024 13:45 |
Last Modified: | 06 Jan 2025 15:47 |
Status: | Published |
Publisher: | Institute of Electrical and Electronics Engineers (IEEE) |
Refereed: | Yes |
Identification Number: | 10.1109/ICSME58944.2024.00037 |
Related URLs: | |
Open Archives Initiative ID (OAI ID): | oai:eprints.whiterose.ac.uk:216884 |