How Do Developers Structure Unit Test Cases? An Empirical Study from the "AAA" Perspective
Chenhao Wei, Lu Xiao, Tingting Yu, Sunny Wong, Abigail Clune

TL;DR
This empirical study investigates how developers structure unit test cases using the AAA pattern, identifies common anti-patterns and design flaws, and explores developer reception to refactoring proposals.
Contribution
It provides the first large-scale analysis of AAA adherence in real-world test cases, identifying anti-patterns, design flaws, and developer attitudes towards refactoring.
Findings
71.5% of test cases follow AAA structure
Identified three anti-patterns deviating from AAA
Found four design flaws in the assert blocks
Abstract
The AAA pattern, i.e. arrange, act, and assert, provides a unified structure for unit test cases, which benefits comprehension and maintenance. However, there is little understanding regarding whether and how common real-life developers structure unit test cases following AAA in practice. In particular, are there recurring anti-patterns that deviate from the AAA structure and merit refactoring? And, if test cases follow the AAA structure, could they contain design flaws in the A blocks? If we propose refactoring to fix the design of test cases following the AAA, how do developers receive the proposals? Do they favor refactoring? If not, what are their considerations? This study presents an empirical study on 435 real-life unit test cases randomly selected from four open-source projects. Overall, the majority (71.5%) of test cases follow the AAA structure. And, we observed three…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsSoftware Engineering Techniques and Practices · Quality and Supply Management
