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
翻译:为了创建单元测试,可能需要重构生产代码,例如通过扩大对特定方法的访问范围或将类分解为更小的单元,以更容易地独立测试。我们报告了一项广泛的研究,以了解这样的复合重构过程,以提高可测试性。我们收集并研究了来自621个GitHub项目的346,841个Java pull request。首先,我们比较了两个种群中的原子重构:有更改的测试对(即具有生产和测试代码的共同更改,因此可能包括可测试性重构)的pull request和没有测试对的pull request。我们发现,在测试对pull request中有更多的原子重构,例如更改变量类型操作或更改参数类型。其次,我们手动分析了200个pull request的代码更改,其中开发人员明确提到了“可测试性”或“重构+测试”等术语。我们为了可测试性确定了十种复合重构过程,我们称之为可测试性重构模式。第三,我们手动分析了额外的524个测试对pull request:既是随机选择的,又是我们假定会发现可测试性重构的,例如关于依赖性或并发性问题的pull request。实际上约25%的所有分析过的pull request都包含可测试性重构模式。最常见的是为覆盖或调用而提取方法,为调用而扩大对方法的访问权限,以及为调用而提取类。我们还报告了与这些模式共存的频繁原子重构,并讨论了我们的研究对研究、实践和教育的影响。