arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2408.01751cs.SE
收藏

论测试代码中断言消息的原理与使用:来自软件从业者的洞见

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

AI总结:

本文通过调查138名专业软件从业者,研究断言消息的使用目的、编写挑战与维护方式,并为高质量断言消息及自动化测试工具改进提供指南。

摘要:

单元测试是一项重要实践,通过一系列测试用例验证软件系统的行为,从而帮助确保软件系统的质量。这些测试用例的核心是断言语句,它使软件从业者能够验证系统行为的正确性。为了帮助理解和排查测试用例失败,从业者可以在断言语句中包含一条消息(即断言消息)。尽管先前的研究已经通过挖掘软件仓库考察了断言消息的频率和结构,但这些研究并未确定断言消息的类型或目的,也未确定从业者如何感知各类断言消息的必要性或使用方式。在本文中,我们调查了138名专业软件从业者,以收集他们关于断言消息的经验和观点的洞见。我们的研究结果表明,大多数调查受访者认为断言消息在排查失败、提高测试可理解性以及充当文档方面具有价值。然而,并非所有受访者都会始终如一地在其断言方法中包含消息。我们还识别了构建有效断言消息的常见考虑因素、编写这些消息时的挑战、维护技术,以及它们与调试过程的集成。我们的结果有助于理解当前实践,并为编写高质量断言消息提供指南,为最佳实践和编码规范奠定基础。此外,这些洞见可以指导自动化单元测试工具的改进,方法是加入对断言消息存在性和质量的检查,并向从业者提供实时反馈。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑