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

例外行为:它们被测试的频率如何?

Exceptional Behaviors: How Frequently Are They Tested?

UFMG(米纳斯吉拉斯联邦大学);University of Passau(帕绍大学)

Andre Hora, Gordon Fraser

AI总结:

本文通过实证研究探讨现实系统中异常行为的测试频率,发现约21.4%的方法在运行时会引发异常,且多数异常行为不频繁,建议开发支持练习异常行为的工具并重构try/except块。

摘要:

异常允许开发人员处理预期发生频率较低的错误情况。理想情况下,良好的测试套件应测试正常和异常行为,以发现更多错误并避免回归问题。尽管当前研究分析传播到测试的异常,但并未探索其他不传播到测试的异常。在本文中,我们进行了一项实证研究,探讨现实世界系统中异常行为被测试的频率。我们考虑了传播到测试的异常和未传播到测试的异常。为此,我们运行了带有仪器的测试套件,监控其执行,并收集运行时引发的异常信息。我们分析了25个Python系统的测试套件,覆盖了5,372个执行的方法、17.9M次调用和1.4M次引发的异常。我们发现,21.4%的执行方法在运行时会引发异常。在引发异常的方法中,中位数为每10次调用中有1次会触发异常行为。接近80%的方法引发异常是不频繁的,但约20%的方法引发异常更频繁。最后,我们为研究人员和实践者提供了启示。我们建议开发支持练习异常行为的新工具,并重构昂贵的try/except块。我们还指出,引发异常的行为不一定是“异常”或罕见的。

英文摘要:

Exceptions allow developers to handle error cases expected to occur infrequently. Ideally, good test suites should test both normal and exceptional behaviors to catch more bugs and avoid regressions. While current research analyzes exceptions that propagate to tests, it does not explore other exceptions that do not reach the tests. In this paper, we provide an empirical study to explore how frequently exceptional behaviors are tested in real-world systems. We consider both exceptions that propagate to tests and the ones that do not reach the tests. For this purpose, we run an instrumented version of test suites, monitor their execution, and collect information about the exceptions raised at runtime. We analyze the test suites of 25 Python systems, covering 5,372 executed methods, 17.9M calls, and 1.4M raised exceptions. We find that 21.4% of the executed methods do raise exceptions at runtime. In methods that raise exceptions, on the median, 1 in 10 calls exercise exceptional behaviors. Close to 80% of the methods that raise exceptions do so infrequently, but about 20% raise exceptions more frequently. Finally, we provide implications for researchers and practitioners. We suggest developing novel tools to support exercising exceptional behaviors and refactoring expensive try/except blocks. We also call attention to the fact that exception-raising behaviors are not necessarily "abnormal" or rare.

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

↑