一句话:实现 PyCharm 插件 PyNOSE,检测 Python 测试代码中的 17 种测试坏味道并开展大规模实证分析。
测试坏味道不仅损害测试代码本身,也会影响被测的生产代码质量,但已有研究多集中于 Java、Scala,Python 尚缺自动化检测工具。本文从既有文献中筛选出在 Python 标准 Unittest 框架下语言无关或功能等价的测试坏味道,共整理出 17 种;并通过挖掘与坏味道引入/修复相关的频繁代码变更模式,提出 Python 特有的 Suboptimal Assert 坏味道。作者将其实现为 PyCharm 插件 PyNOSE,并对大量 Python 项目开展大规模实证分析,发现 98% 的项目与 84% 的测试套件至少存在一种测试坏味道,而新提出的 Suboptimal Assert 出现在 70.6% 的项目中。
Similarly to production code, code smells also occur in test code, where they are called test smells. Test smells have a detrimental effect not only on test code but also on the production code that is being tested. To date, the majority of the research on test smells has been focusing on programming languages such as Java and Scala. However, there are no available automated tools to support the identification of test smells for Python, despite its rapid growth in popularity in recent years. In this paper, we strive to extend the research to Python, build a tool for detecting test smells in this language, and conduct an empirical analysis of test smells in Python projects.We started by gathering a list of test smells from existing research and selecting test smells that can be considered language-agnostic or have similar functionality in Python’s standard Unittest framework. In total, we identified 17 diverse test smells. Additionally, we searched for Python-specific test smells by mining frequent code change patterns that can be considered as either fixing or introducing test smells. Based on these changes, we proposed our own test smell called Suboptimal Assert. To detect all these test smells, we developed a tool called PYNOSE in the form of a plugin to PyCharm, a popular Python IDE. Finally, we conducted a large-scale empirical investigation aimed at analyzing the prevalence of test smells in Python code. Our results show that 98% of the projects and 84% of the test suites in the studied dataset contain at least one test smell. Our proposed Suboptimal Assert smell was detected in as much as 70.6% of the projects, making it a valuable addition to the list.
DOI 原文 ·
@inproceedings{paperbot6508,
title = {PyNose: A Test Smell Detector For Python},
author = {Tongjie Wang and Yaroslav Golubev and Oleg Smirnov and Jiawei Li and Timofey Bryksin and Iftekhar Ahmed},
booktitle = {ASE},
year = {2021},
doi = {10.1109/ase51524.2021.9678615}
}