How to make JUnit test cases to run in sequential order?

Athiruban picture Athiruban · Mar 12, 2012 · Viewed 44.2k times · Source

I am using JUnit4.

I have a set of test methods in a test case.

Each test method inserts some records and verify a test result and finally delete the records inserted.

Since the JUnit run in parallel, test methods fail because of some records present during the execution of previous test method. This happen only in my colleague machine(Windows 7), not in my machine(Cent OS 6).

What we need is that the test methods have to pass in all our machines.

I have tried clearing the records in the Setup() method but again it works only on my machine. Is there any option available in JUnit to make the test methods to run in a uniform sequential order ?

Thanks,

Answer

Aleksandr Dubinsky picture Aleksandr Dubinsky · Dec 17, 2012

JUnit 4.11 now supports specifying execution order using @FixMethodOrder annotation.