arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2507.01477cs.SE
收藏

结合Python的类型推断与自动单元测试生成

Combining Type Inference and Automated Unit Test Generation for Python

University of Passau(帕绍大学);JetBrains Research(JetBrains 研究)

Lukas Krodinger, Stephan Lukasczyk, Gordon Fraser

AI总结:

研究针对Python动态类型语言缺乏类型信息阻碍单元测试生成的问题,通过在Pynguin框架扩展类型跟踪,利用测试执行提取类型信息,实现推断参数类型、记录返回值类型并增加代码覆盖率,提升了分支覆盖率和变异分数。

摘要:

自动单元测试生成是一个既定的研究领域,目前主要集中在静态类型编程语言上。像Python这样的动态类型编程语言缺乏类型信息,这阻碍了严重依赖函数参数和返回类型信息来选择合适测试用例参数的测试生成器。由于自动测试生成器本质上依赖于候选测试的频繁执行,我们通过引入类型跟踪来利用这些频繁执行解决此问题,类型跟踪在执行期间提取类型相关信息并逐步完善可用类型信息。我们将类型跟踪实现为Python的Pynguin测试生成框架的扩展,使其能够通过观察运行时参数的使用推断参数类型、记录函数调用返回值的类型,并使用此类型信息增加代码覆盖率。该方法使分支覆盖率提高了87.8%,改进了变异分数,且生成的类型信息质量与其他先进类型推断工具相当。

英文摘要:

Automated unit test generation is an established research field that has so far focused on statically-typed programming languages. The lack of type information in dynamically-typed programming languages, such as Python, inhibits test generators, which heavily rely on information about parameter and return types of functions to select suitable arguments when constructing test cases. Since automated test generators inherently rely on frequent execution of candidate tests, we make use of these frequent executions to address this problem by introducing type tracing, which extracts type-related information during execution and gradually refines the available type information. We implement type tracing as an extension of the Pynguin test-generation framework for Python, allowing it (i) to infer parameter types by observing how parameters are used during runtime, (ii) to record the types of values that function calls return, and (iii) to use this type information to increase code coverage. The approach leads to up to 87.8 % more branch coverage, improved mutation scores, and to type information of similar quality to that produced by other state-of-the-art type-inference tools.

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

↑