Unit testing is a vital part of the software development process and involves developers writing code to verify or assert production code. Furthermore, to help comprehend the test case and troubleshoot issues, developers have the option to provide a message that explains the reason for the assertion failure. In this exploratory empirical study, we examine the characteristics of assertion messages contained in the test methods in 20 open-source Java systems. Our findings show that while developers rarely utilize the option of supplying a message, those who do, either compose it of only string literals, identifiers, or a combination of both types. Using standard English readability measuring techniques, we observe that a beginner's knowledge of English is required to understand messages containing only identifiers, while a 4th-grade education level is required to understand messages composed of string literals. We also discuss shortcomings with using such readability measuring techniques and common anti-patterns in assert message construction. We envision our results incorporated into code quality tools that appraise the understandability of assertion messages.
翻译:单元测试是软件开发过程中的关键环节,涉及开发者编写代码来验证或断言生产代码。此外,为帮助理解测试用例并排查问题,开发者可以选择提供一条解释断言失败原因的消息。在这项探索性实证研究中,我们分析了20个开源Java系统测试方法中断言消息的特征。研究结果表明,虽然开发者很少使用提供消息的选项,但那些使用该选项的开发者,要么仅由字符串字面量组成,要么仅由标识符组成,或同时包含这两种类型。通过使用标准英语可读性测量技术,我们观察到,理解仅包含标识符的消息需要初学者的英语知识水平,而理解由字符串字面量组成的消息则需要四年级的教育水平。我们还讨论了使用此类可读性测量技术的局限性以及断言消息构造中常见的反模式。我们设想将研究结果整合到代码质量工具中,用于评估断言消息的可理解性。