0

I'm currently trying to figure out why some integration tests only fail on Linux machines (and know that test order affecting test results is a bad thing).

When I run the maven target on Windows machines, the order of the test classes is pretty much preserved between runs and across two different machines.

When I run the maven target on Linux machines, the order of the test classes is different between Linux machines (did not check for across builds).

How does maven determine the order of test classes that will run?

EDIT: I am not trying to control the order of the tests, but am trying to determine how maven decides what order to run these tests, which is not answered in How do I control the order of execution of tests in Maven?

Community
  • 1
  • 1
neverendingqs
  • 4,006
  • 3
  • 29
  • 57
  • This isn't a duplicate unless I'm mistaken. I'm not looking to control the order of the tests, but am asking how maven decides what order. – neverendingqs Sep 08 '15 at 13:40
  • The other question was solved by saying it could be set to order alphabetically. This question asks what the default ordering is. I have seen on Windows it's always the same order across all developers, but on Linux, it's usually different. – GeertPt Sep 08 '15 at 13:49

1 Answers1

1

There is no guarantee to the order in which test will run.

There should be no need for tests to be in order. If you need the tests to run in order, you are not writing proper tests.

You should be able to run any test on it's own, at any time. The reason for this is that if, for example, you create an object in one test and use it in another test, if the creation test fails, the next test will fail by default.

Nicholas Robinson
  • 1,359
  • 1
  • 9
  • 20
  • 2
    Agreed. Unfortunately, I'm trying to fix a build where this might not be the case. – neverendingqs Sep 08 '15 at 13:38
  • One thing you can do, if you need order is: before each test, reset the state. Then in your test call all the prerequisite tests like methods, you will unfortunately have to deal with any exceptions manually. And then execute the test code. If you are using junit 4.* you can look into the `@Before` annotation to reset the state (it runs before each test) – Nicholas Robinson Sep 08 '15 at 15:15