Reputation: 1126
Is there a way to run truly random unit tests in JUnit? I want to do a bunch of test runs with my tests in truly random order to try to detect test pollution. It seems like the best I can do is put @TestMethodOrder(MethodOrderer.Random.class) at the class levels, but classes can still unfortunately share variables.
Upvotes: 2
Views: 510
Reputation: 12021
On test class level you can indeed randomize the executing of your tests using @TestMethodOrder(MethodOrderer.Random.class)
.
The default behavior of JUnit 5 also ensures to create a new instance of your test class for each test method, so I guess
... but classes can still, unfortunately, share variable
Shouldn't be a problem here.
That would randomize the test execution order of your tests inside a class, but as far as I know there is currently no way to set the order of which test classes are picked when. There is an on-going discussion for this on GitHub.
Upvotes: 2