On the Rationale and Use of Assertion Messages in Test Code: Insights from Software Practitioners

Anthony Peruma,Taryn Takebayashi,Rocky Huang,Joseph Carmelo Averion,Veronica Hodapp,Christian D. Newman,Mohamed Wiem Mkaouer
2024-08-03
Abstract:Unit testing is an important practice that helps ensure the quality of a software system by validating its behavior through a series of test cases. Core to these test cases are assertion statements, which enable software practitioners to validate the correctness of the system's behavior. To aid with understanding and troubleshooting test case failures, practitioners can include a message (i.e., assertion message) within the assertion statement. While prior studies have examined the frequency and structure of assertion messages by mining software repositories, they do not determine their types or purposes or how practitioners perceive the need for or the usage of various types of assertion messages. In this paper, we survey 138 professional software practitioners to gather insights into their experience and views regarding assertion messages. Our findings reveal that a majority of survey respondents find assertion messages valuable for troubleshooting failures, improving test understandability, and serving as documentation. However, not all respondents consistently include messages in their assertion methods. We also identified common considerations for constructing effective assertion messages, challenges in crafting them, maintenance techniques, and their integration into debugging processes. Our results contribute to the understanding of current practices and provide guidelines for authoring high-quality assertion messages, serving as a foundation for best practices and coding standards. Furthermore, the insights can guide the improvement of automated unit testing tools by incorporating checks for the presence and quality of assertion messages and providing real-time feedback to practitioners.
Software Engineering
What problem does this paper attempt to address?
### What problems does this paper attempt to solve? This paper aims to explore and understand the usage, construction methods, maintenance approaches of unit test assertion messages in software development, as well as their integration in the development and debugging processes. Specifically, the research objective is to gain an understanding of practitioners' views, construction, maintenance, and effectiveness of assertion messages by directly collecting insights from professional software practitioners. #### Research Background Unit testing is an important practice for ensuring software quality, in which assertion statements are used to verify whether the behavior of the code meets expectations. To help understand and troubleshoot the reasons for test failures, many unit test frameworks allow for an optional message parameter, namely the assertion message, to be included in the assertion statement. Although previous studies have analyzed the frequency and structure of assertion messages, they have not delved into the specific types, uses, and practitioners' actual usage perceptions of assertion messages. #### Main Problems 1. **Frequency and Reasons for Using Assertion Messages**: Researchers hope to understand through surveys the extent to which practitioners include assertion messages and explore their motivations for doing so. 2. **How to Construct Assertion Messages**: Understand how practitioners usually construct assertion messages in order to better understand their thought processes and thus create effective assertion messages. 3. **Maintenance of Assertion Messages**: Research how assertion messages remain relevant and accurate throughout the entire development life cycle to provide insights into unit test best practices. 4. **Integration of Assertion Messages in Development and Debugging**: Research how practitioners use assertion messages to troubleshoot test case failures, providing a basis for improving tools and test practices. #### Research Contributions - Provide quantitative and qualitative insights from professional software engineers, revealing their usage experiences and views on assertion messages. - Expand the body of knowledge on unit test best practices to improve the quality and maintainability of test suites. - Propose improvement suggestions to guide the development of unit test frameworks and code quality tools. By answering these questions, this research fills the gap in understanding the actual value and impact of assertion messages, helps improve test frameworks, develop better tools, and support best practices in software testing and debugging, and ultimately enhances practitioners' productivity and overall software quality.