拉式请求中的可测试性重构:模式与趋势
Testability Refactoring in Pull Requests: Patterns and Trends
摘要:
要创建单元测试,可能需要重构产品代码,例如通过扩展对特定方法的访问或通过将类分解为更小的单元,这些单元更容易独立测试。我们报告了一项广泛的研究,以了解这种复合重构程序的目的,提高可测试性。我们收集并研究了来自621个GitHub项目的346,841个Java Pull请求。首先,我们比较了两个群体中的原子重构:具有更改的测试对的拉取请求(即,生产和测试代码中的共同更改,因此可能包括可测试性重构)和没有测试对的拉取请求。我们在测试对拉取请求中发现了更多的原子重构,例如更改变量类型操作或更改参数类型。其次,我们手动分析了200个拉取请求的代码更改,其中开发人员明确提到了术语“可测试性”或“重构+测试”。我们确定了10个复合重构过程,以达到可测试性的目的,我们称之为可测试性重构模式。第三,我们手动分析了另外524个测试对拉取请求:都是随机选择的,我们假设在其中找到可测试性重构,例如在关于依赖或并发问题的拉取请求中。在所有分析的拉取请求中,大约有25%实际上包含了可测试性重构模式。最常见的是提取一个方法用于覆盖或调用,扩大对方法的访问以进行调用,以及提取一个类以进行调用。我们还报告了与模式同时发生的频繁原子重构,并讨论了我们的研究结果对研究、实践和教育的影响
英文摘要:
To create unit tests, it may be necessary to refactor the production code, e.g. by widening access to specific methods or by decomposing classes into smaller units that are easier to test independently. We report on an extensive study to understand such composite refactoring procedures for the purpose of improving testability. We collected and studied 346,841 java pull requests from 621 GitHub projects. First, we compared the atomic refactorings in two populations: pull requests with changed test-pairs (i.e. with co-changes in production and test code and thus potentially including testability refactoring) and pull requests without test-pairs. We found significantly more atomic refactorings in test-pairs pull requests, such as Change Variable Type Operation or Change Parameter Type. Second, we manually analyzed the code changes of 200 pull requests, where developers explicitly mention the terms "testability" or "refactor + test". We identified ten composite refactoring procedures for the purpose of testability, which we call testability refactoring patterns. Third, we manually analyzed additional 524 test-pairs pull requests: both randomly selected and where we assumed to find testability refactorings, e.g. in pull requests about dependency or concurrency issues. About 25% of all analyzed pull requests actually included testability refactoring patterns. The most frequent were extract a method for override or for invocation, widen access to a method for invocation, and extract a class for invocation. We also report on frequent atomic refactorings which co-occur with the patterns and discuss the implications of our findings for research, practice, and education
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。