Thomas Sundberg

May 3, 2012

Execute tests in random order

Filed under: Java, Maven, TDD — Tags: , , — Thomas Sundberg @ 17:16

This post has been migrated to

It works on my machine!

Ever heard that from a developer? I have, and it happens that the reason is that it actually works on their machine. It may also be the case that the order in which tests are executed matters. Test classes depends on each other and the order they are executed in is important. The solution is to execute the tests in random order so that any dependencies between tests are found and can be removed.

You can specify the order test classes are fed to Surefire in Maven. The order in which the tests are executed in a test class is not possible to influence as far as I know. You have to set a configuration runOrder in the Surefire plugin. You may specify different run orders and the one I would use to find dependent test is random

<?xml version="1.0" encoding="UTF-8"?>

This will ensure that the test classes are executed in different order and any dependencies between them will eventually pop up.


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at

%d bloggers like this: