TY - JOUR
T1 - How Do Developers Structure Unit Test Cases? An Empirical Analysis of the AAA Pattern in Open Source Projects
AU - Wei, Chenhao
AU - Xiao, Lu
AU - Yu, Tingting
AU - Wong, Sunny
AU - Clune, Abigail
N1 - Publisher Copyright:
© 2025 IEEE.
PY - 2025
Y1 - 2025
N2 - The AAA (Arrange, Act, Assert) pattern provides a unified structure for unit test cases, potentially benefiting comprehension and maintenance. However, its adoption and implementation in practice remain insufficiently understood. This study investigates the prevalence of AAA pattern usage, identifies recurring deviations and design issues within AAA structures, and assesses developers' receptiveness to AAA-based improvements.We conducted an empirical study on 735 real-life unit test cases randomly selected from seven open-source projects. We manually analyzed these test cases, identified AAA-related issues, and proposed fixes to developers. Our analysis found that 77% of test cases follow the AAA structure. We identified three recurring patterns deviating from AAA and four design issues within A blocks. Comparison with classic test smells revealed unique insights provided by AAA analysis. Of 27 improvement proposals sent to developers, 78% received positive feedback. These findings show that the AAA pattern is widely adopted in practice, but deviations from and design issues within AAA patterns are common. Our analysis provides a novel perspective on test case quality, complementing traditional test smell analysis. The high acceptance rate of our improvement proposals suggests that developers value AAA-based enhancements. These findings can guide the development of tools for improving AAA practice in unit tests.
AB - The AAA (Arrange, Act, Assert) pattern provides a unified structure for unit test cases, potentially benefiting comprehension and maintenance. However, its adoption and implementation in practice remain insufficiently understood. This study investigates the prevalence of AAA pattern usage, identifies recurring deviations and design issues within AAA structures, and assesses developers' receptiveness to AAA-based improvements.We conducted an empirical study on 735 real-life unit test cases randomly selected from seven open-source projects. We manually analyzed these test cases, identified AAA-related issues, and proposed fixes to developers. Our analysis found that 77% of test cases follow the AAA structure. We identified three recurring patterns deviating from AAA and four design issues within A blocks. Comparison with classic test smells revealed unique insights provided by AAA analysis. Of 27 improvement proposals sent to developers, 78% received positive feedback. These findings show that the AAA pattern is widely adopted in practice, but deviations from and design issues within AAA patterns are common. Our analysis provides a novel perspective on test case quality, complementing traditional test smell analysis. The high acceptance rate of our improvement proposals suggests that developers value AAA-based enhancements. These findings can guide the development of tools for improving AAA practice in unit tests.
KW - AAA pattern
KW - Design Quality
KW - Refactoring
KW - Software Testing
KW - Test Smell
KW - Unit Testing
UR - http://www.scopus.com/inward/record.url?scp=85217256953&partnerID=8YFLogxK
UR - http://www.scopus.com/inward/citedby.url?scp=85217256953&partnerID=8YFLogxK
U2 - 10.1109/TSE.2025.3537337
DO - 10.1109/TSE.2025.3537337
M3 - Article
AN - SCOPUS:85217256953
SN - 0098-5589
JO - IEEE Transactions on Software Engineering
JF - IEEE Transactions on Software Engineering
ER -