Research · Software Testing
What Is Test Prioritization in Software Testing?
Test prioritization is the practice of reordering a test suite so that the most important or most revealing tests run first. The goal is to detect failures sooner, reduce build time, and surface problems — including flaky test behaviour — earlier in the CI/CD pipeline.
By Hasnain Iqbal · Updated 1 April 2025
Why Test Prioritization Matters
As software projects grow, test suites grow with them. Running thousands of tests sequentially takes time — sometimes hours. Developers waiting for CI feedback slow down: they context-switch, work on unrelated tasks, or lose the flow of the change they were making.
Test prioritization addresses this by running the tests most likely to fail (or most likely to reveal relevant information) first. When a failure occurs early in the run, the CI build fails fast, the developer gets feedback within minutes rather than hours, and the rest of the suite can be skipped.
This matters especially for large-scale software systems where a full test run might take 30 minutes or more.
Prioritization Strategies
History-based prioritization — tests that have failed recently are likely to fail again. Sort by recent failure rate.
Coverage-based prioritization — tests that cover the code changed in the current commit are most likely to catch regressions related to that change. Sort by coverage overlap with the diff.
Fault-detection maximization — use code coverage data to order tests so that each successive test covers the maximum number of yet-uncovered statements.
Risk-based prioritization — weight tests by the risk of the code they cover (e.g., critical payment paths ranked above rarely-used admin features).
Order-dependent flaky test prioritization — a specialised strategy: identify pairs of tests most likely to have an order-dependency relationship, and prioritise running those pairs in the orderings most likely to surface the dependency. This is the approach explored in my published research.
Test Prioritization and Flaky Tests
Detecting order-dependent flaky tests requires running a test suite in many different orderings — a potentially enormous search space. For a suite of N tests, there are N! orderings to explore.
Prioritization dramatically reduces this space. By analysing which tests access shared state (databases, statics, environment variables), we can predict which test pairs are likely to have a polluter-victim relationship. These pairs are then prioritised for re-execution in orderings that would expose the relationship.
My research at IIT, University of Dhaka (published at the International Flaky Tests Workshop, IEEE/ACM ICSE 2025) proposes a prioritization approach that significantly reduces the number of test re-runs required to detect OD flaky tests, making the detection process practical for large CI/CD pipelines.
Implementing Test Prioritization
Most modern CI systems support some form of test prioritization.
Jest (JavaScript) — supports running failed tests first via --testPathPattern and supports custom sequencers that can implement history-based ordering.
pytest (Python) — the pytest-ordering and pytest-randomly plugins provide ordering control. The pytest-failed-first plugin implements history-based prioritization.
JUnit 5 (Java) — the @TestMethodOrder annotation supports custom ordering strategies including random and display-name-based.
CI/CD tools — GitHub Actions, CircleCI, and BuildKite all support test parallelisation with automatic splitting based on historical timing data, which is a form of implicit prioritization.
Related research
I published research on this topic at the International Flaky Tests Workshop (FTW), co-located with IEEE/ACM ICSE 2025 — exploring how to prioritise potential order-dependent flaky tests to reduce CI re-run costs.
Read the paper →Frequently asked questions
What is test prioritization?▼
Test prioritization is the practice of ordering tests so that the most valuable ones — most likely to fail, most relevant to recent changes, or most revealing — run first. It reduces feedback time in CI/CD pipelines.
How does test prioritization help with flaky tests?▼
For order-dependent flaky tests, prioritization helps by identifying which test pairs are most likely to have a polluter-victim relationship and testing those orderings first. This reduces the enormous search space of possible test orderings.
What is coverage-based test prioritization?▼
Coverage-based prioritization orders tests so that each successive test covers the maximum number of code statements not yet covered by earlier tests. It maximises the fault-detection capability of the first N tests in the run.
Can test prioritization speed up CI builds?▼
Yes. By running tests most likely to fail first, prioritization enables CI builds to fail fast — stopping the run as soon as a failure is found. This can significantly reduce the average time developers wait for feedback.
Related topics
What Are Flaky Tests?
Flaky tests are automated tests that produce different results — pass or fail — without any change to the source code. Learn what causes them, why they matter, and how to address them in CI/CD pipelines.
What Are Order-Dependent Flaky Tests?
Order-dependent (OD) flaky tests are tests that only fail when run after a specific other test. They are a significant source of CI/CD instability. Learn how they work, how to detect them, and how to fix them.
Software Testing in CI/CD Pipelines
CI/CD pipelines depend on reliable automated test suites. Learn how testing integrates with continuous integration and delivery, the common pitfalls, and strategies for keeping pipelines fast and trustworthy.