Skip to content

[SUREFIRE-859] Make random test order reproducible - #3421

Merged
slachiewicz merged 1 commit into
apache:masterfrom
wilx:issue-859-reproducible-random-order
Aug 10, 2026
Merged

slachiewicz merged 1 commit into
apache:masterfrom
wilx:issue-859-reproducible-random-order

Conversation

@wilx

@wilx wilx commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • sort discovered test classes before applying the seeded random shuffle
  • pass Surefire's runOrderRandomSeed to JUnit Jupiter as junit.jupiter.execution.order.random.seed
  • propagate run-order provider properties consistently in forked and in-process execution
  • preserve an explicitly configured JUnit Jupiter random seed
  • add unit and integration coverage for deterministic discovery order and JUnit seed propagation

Why

Collections.shuffle() is deterministic only when both its input order and seed are deterministic. Test-class discovery can return classes in a different order across filesystems and machines, so the same Surefire seed previously produced different shuffled orders.

JUnit Jupiter also performs its own class and method ordering. Surefire selected Jupiter's random orderers for runOrder=random, but did not pass runOrderRandomSeed to JUnit. Jupiter therefore used an independent seed and could not reproduce the complete test order from the Surefire seed.

Sorting the discovered classes before shuffling provides a stable input. Forwarding the same seed through JUnit's configuration parameters makes Jupiter's random class and method ordering reproducible as well. An explicit junit.jupiter.execution.order.random.seed in Surefire's JUnit configuration parameters retains precedence.

Fixes #859

Validation

  • mvn clean install passed across all 17 reactor modules on JDK 17
  • mvn -Prun-its clean install passed; surefire-its ran 764 tests with no failures or errors
  • focused RunOrderIT passed all 11 tests, including JUnit seed propagation with forkCount=0 and forkCount=1
  • focused Surefire API, common, and JUnit Platform provider unit tests passed
  • Spotless, Checkstyle, RAT, and git diff --check passed

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean install to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its clean install).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

Sort discovered test classes before shuffling so a seed produces the same order across filesystems and machines. Forward the Surefire random seed to JUnit Jupiter for deterministic class and method ordering.

Fixes apache#859
@wilx
wilx marked this pull request as ready for review August 9, 2026 16:22
@slachiewicz

Copy link
Copy Markdown
Member

@wilx could You add labels to PR?

@slachiewicz slachiewicz added the bug Something isn't working label Aug 9, 2026
@wilx

wilx commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

@wilx could You add labels to PR?

I don't think I have the privileges. I don't see the cog wheel.

@slachiewicz
slachiewicz merged commit bf39524 into apache:master Aug 10, 2026
14 checks passed
@github-actions github-actions Bot added this to the 3.6.0-M2 milestone Aug 10, 2026
@wilx
wilx deleted the issue-859-reproducible-random-order branch August 10, 2026 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Random Seed does not lead to reproducible run order on different machines

2 participants