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

测试行为,而非方法!检测被方法所痴迷的测试

Test Behaviors, Not Methods! Detecting Tests Obsessed by Methods

UFMG(米纳斯吉拉斯联邦大学);Delft University of Technology(代尔夫特理工大学)

Andre Hora, Andy Zaidman

AI总结:

本文提出一种新的测试气味"Test Obsessed by Method",通过运行时分析发现测试方法覆盖单一生产方法的多个路径,分析了Python标准库中44个此类测试的行为和特征。

摘要:

最佳的测试实践指出,测试应验证系统的单一功能或行为。验证多个行为的测试更难理解,缺乏焦点,并且更耦合到生产代码。试图识别这一问题的尝试是测试气味"Eager Test",其旨在捕捉基于生产方法调用数量的测试,这些测试验证了过多的功能。不幸的是,先前的研究表明,计数生产方法调用是一个不准确的度量,因为这些调用并不可靠地作为功能的代理。我们设想了一种互补的解决方案,基于运行时分析:我们假设一些验证多个行为的测试很可能覆盖同一个生产方法的多个路径。因此,我们提出了一种新的测试气味,名为"Test Obsessed by Method",即一个测试方法覆盖了单一生产方法的多个路径。我们提供了一个初步的实证研究,以探索这种气味在2054个由12个Python标准库测试套件提供的测试中的存在情况。(1)我们在12个测试套件中的11个中检测到44个"Test Obsessed by Methods"。(2)每个气味测试验证生产方法的中位数为两个行为。(3)44个气味测试可以分为118个新测试。(4)23%的气味测试有代码注释指出正在测试不同的行为。我们最后讨论了好处、限制和进一步的研究。

英文摘要:

Best testing practices state that tests should verify a single functionality or behavior of the system. Tests that verify multiple behaviors are harder to understand, lack focus, and are more coupled to the production code. An attempt to identify this issue is the test smell \emph{Eager Test}, which aims to capture tests that verify too much functionality based on the number of production method calls. Unfortunately, prior research suggests that counting production method calls is an inaccurate measure, as these calls do not reliably serve as a proxy for functionality. We envision a complementary solution based on runtime analysis: we hypothesize that some tests that verify multiple behaviors will likely cover multiple paths of the same production methods. Thus, we propose a novel test smell named \emph{Test Obsessed by Method}, a test method that covers multiple paths of a single production method. We provide an initial empirical study to explore the presence of this smell in 2,054 tests provided by 12 test suites of the Python Standard Library. (1) We detect 44 \emph{Tests Obsessed by Methods} in 11 of the 12 test suites. (2) Each smelly test verifies a median of two behaviors of the production method. (3) The 44 smelly tests could be split into 118 novel tests. (4) 23% of the smelly tests have code comments recognizing that distinct behaviors are being tested. We conclude by discussing benefits, limitations, and further research.

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

↑