0

I have a java project and I have to launch the methods of a test class in random order. Is there a way to do that with Maven?

I tried with surefire and runOrder, but the configuration works with a test suite, in fact it launches the classes in random order but not the methods within them.

ValeSwire
  • 33
  • 5
  • Tests should be as reproducible as possible. Running them in random order makes this more difficult. – J Fabian Meier Mar 03 '20 at 08:44
  • You should use JUnit Jupiter which can execute test method explicitly in random order https://junit.org/junit5/docs/current/user-guide/#writing-tests-test-execution-order – khmarbaise Mar 03 '20 at 08:51
  • @khmarbaise The project has junit4, so I can't use Jupiter. – ValeSwire Mar 03 '20 at 09:00
  • @JFMeier I somewhat disagree - running tests in random order might reveal hidden dependencies between tests – Gyro Gearless Mar 03 '20 at 09:20
  • Is using `MethodSorters.JVM` per [The JUnit Wiki](https://github.com/junit-team/junit4/wiki/Test-execution-order) good enough for your purpose? – RealSkeptic Mar 03 '20 at 09:23
  • @GyroGearless Investigating this is certainly useful. I just fear that I change something, run the tests again, get a red test and don't know whether this comes from my test or some hidden dependency. – J Fabian Meier Mar 03 '20 at 09:25
  • Junit 4 does not support explicitly run in random order JUnit Jupiter does... – khmarbaise Mar 03 '20 at 09:46
  • actually, the order of the test methods is not guaranteed: https://stackoverflow.com/questions/3693626/how-to-run-test-methods-in-specific-order-in-junit4 – Dmitrii Bocharov Mar 03 '20 at 10:21

0 Answers0