Abstract
Flaky tests—tests that yield inconsistent results on the same code version—significantly hinder Continuous Integration (CI) workflows by delaying releases and eroding developer trust. While existing tools focus on detecting flakiness through reruns, localizing the root cause within the application code remains a manual and grueling challenge. This paper addresses this "localization gap" by repurposing Spectrum-Based Fault Localization (SBFL) and augmenting it with change history and code metrics. By evaluating the approach on five large-scale Java projects, the researchers demonstrate that their ensemble model can pinpoint the responsible "flaky class" in the top 5 suggestions nearly half the time, substantially reducing the manual effort required for debugging.
Introduction
In modern software development, Continuous Integration (CI) pipelines are the backbone of quality assurance. However, these pipelines are frequently disrupted by flaky tests: tests that pass or fail intermittently without any changes to the underlying code. These tests waste expensive compute resources and, more critically, lead developers to ignore genuine test failures.
While the industry has made strides in detecting flakiness, fixing it remains a bottleneck. Once a test is identified as flaky, developers must search through the entire execution path to find the non-deterministic logic. This paper shifts the focus from detection to localization, proposing a method to identify the specific classes in the Code Under Test (CUT) responsible for the instability.
Methodology
The researchers treat flakiness localization as a specialized variation of traditional Fault Localization (FL). Their multi-layered approach includes:
- Adapted SBFL: Traditional Spectrum-Based Fault Localization formulas (such as Ochiai, Barinel, Tarantula, and DStar) typically compare passing versus failing runs. The authors adapted these to compare "stable" versus "flaky" runs, identifying classes whose execution is most highly correlated with intermittent failures.
- Genetic Programming (GP): To move beyond off-the-shelf formulas, the team used GP to evolve optimal mathematical expressions that combine various SBFL metrics, effectively learning how to weight different signals for maximum accuracy.
- Feature Augmentation: The model incorporates more than just coverage data. It includes:
- Change Metrics: Data on how frequently a class has changed and the number of unique developers who have modified it.
- Size Metrics: Standard complexity measures like Lines of Code (LOC) and cyclomatic complexity.
- Flakiness-Specific Metrics: Static analysis designed to find suspicious patterns such as asynchronous waits, concurrent calls, or the use of
random()functions. - Ensemble Learning: Finally, a voting mechanism combines the outputs of multiple models to provide a final ranking of the most likely culprit classes.
Experimental Setup
The study was conducted using a ground-truth dataset mined from five major Open Source Java projects: Hbase, Ignite, Pulsar, Alluxio, and Neo4j.
The authors searched GitHub for "flakiness-fixing commits"—instances where developers explicitly documented a fix for a flaky test. After rigorous filtering to ensure the fix resided in the application source code rather than the test script itself, they established a dataset of 38 flakiness-fixing commits involving 63 individual flaky classes.
Key Insights and Results
Localization Performance
The results indicate that localizing flakiness is achievable with high precision. The best-performing ensemble model achieved:
- Top-1 Accuracy: The responsible class was the first suggestion in 26% of cases.
- Top-5 Accuracy: The responsible class was within the top five suggestions in 47% of cases.
- Effort Reduction: On average, a developer would only need to inspect 19% of the classes covered by a flaky test to find the root cause, a significant improvement over manual searching.
The Power of Change History
One of the most significant findings was the impact of change metrics. Adding "churn" data (how often a class is modified) boosted Top-1 accuracy from 13% to 24%. This suggests that flakiness often hides in code that is frequently modified or handled by many different contributors, making it a "smoking gun" for instability.
The "Test vs. CUT" Divide
Interestingly, static metrics specifically designed to detect flakiness (like counting asynchronous waits) were less effective when applied to the application code than when applied to tests. The authors suggest this is because existing flakiness taxonomies are heavily biased toward how flakiness manifests in test scripts. The root cause in the application code may follow different patterns that are not yet fully categorized.
Conclusion and Future Work
This research demonstrates that SBFL, when combined with change history and size metrics, is a powerful tool for reducing the manual burden of fixing flaky tests. The approach is particularly effective for Concurrency and Asynchronous Wait issues, which are among the most common sources of non-determinism.
However, challenges remain. The model's performance drops on high-level integration tests that cover hundreds of classes, and the current dataset is limited to Java. Future work will focus on expanding the dataset, exploring other programming languages, and developing new taxonomies that specifically characterize flakiness from the perspective of the Code Under Test (CUT).
Summary updated