# Testability Refactoring in Pull Requests: Patterns and Trends

**Authors:** Pavel Reich, Walid Maalej  
**arXiv:** [2303.14253](https://arxiv.org/abs/2303.14253)  
**Date:** 2023-03-24  
**Summary page:** https://www.summarizepaper.com/en/paper/2303.14253v1/

## Key points

- Creating unit tests is crucial for ensuring code quality and reliability in software development.
- Refactoring production code may be necessary to create effective unit tests.
- Pavel Reich and Walid Maalej analyzed 346,841 Java pull requests from 621 GitHub projects to identify composite refactoring procedures aimed at improving testability.
- Significantly more atomic refactorings were found in pull requests with changed test-pairs compared to those without test-pairs.
- Extract a method for override or invocation, widen access to a method for invocation, and extract a class for invocation are common patterns identified in the manual analysis of 200 pull requests where developers explicitly mentioned terms like "testability" or "refactor + test".
- About 25% of all analyzed pull requests related to dependency or concurrency issues included one or more of these patterns.
- This study provides insight into frequent atomic refactorings that co-occur with these patterns and discusses their implications for research, practice, and education in software development.

## Summary

In software development, creating unit tests is crucial for ensuring the quality and reliability of the code. To create effective unit tests, it may be necessary to refactor the production code. This can involve widening access to specific methods or decomposing classes into smaller units that are easier to test independently. Pavel Reich and Walid Maalej conducted an extensive analysis of composite refactoring procedures aimed at improving testability. They collected and studied 346,841 Java pull requests from 621 GitHub projects. The researchers compared atomic refactorings in two populations: pull requests with changed test-pairs (i.e., with co-changes in production and test code) and those without test-pairs. They found significantly more atomic refactorings in test-pairs pull requests such as Change Variable Type Operation or Change Parameter Type. Additionally, they manually analyzed 200 pull requests where developers explicitly mentioned terms like "testability" or "refactor + test". These patterns included extract a method for override or invocation, widen access to a method for invocation, and extract a class for invocation. Furthermore, they manually analyzed 524 randomly selected test-pair pull requests related to dependency or concurrency issues where they expected to find testability refactorings; about 25% of all analyzed pull requests included one or more of these patterns. This study provides insight into frequent atomic refactorings that co-occur with these patterns and discusses their implications for research, practice, and education in software development by identifying composite refactoring procedures aimed at improving testability which could provide guidance for developers seeking to create effective unit tests while minimizing disruption to existing codebases.
