Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can surefire and failsafe plugin deliberately randomize execution order of test classes?

It appears that surefire and failsafe plugins execute test classes in order while tests defined within a class execute in undetermined order.

To discover tests which rely on order (what we consider bad tests) we want to force the order to be different for each run. Ideally, we'd have a mechanism to disable randomization or a seed number that would repeat the order (must like the old palm OS emulator had a seed number that drove a sequence of random tests).

Let me know if you know a way to do this? If not, I guess I can work one into a local fork and then submit it.

Thanks

Peter

like image 947
Peter Kahn Avatar asked Feb 14 '23 22:02

Peter Kahn


1 Answers

Some of the other answers link to the surefire maven documentation page, but like most maven documentation it provides no examples of how to actually specify the settings in the maven XML morass. Here is how to do it with the surefire plugin:

<properties>
  <surefire.plugin.version>2.16</surefire.plugin.version>
</properties>

<build>
 <plugins>
   <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-surefire-plugin</artifactId>
     <version>${surefire.plugin.version}</version>
     <configuration>
       <runOrder>random</runOrder>
     </configuration>
   </plugin>
 </plugins>
</build>
like image 116
quux00 Avatar answered Feb 27 '23 11:02

quux00