This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Do we have any way (apart from using suite() method) to ensure that the methods of a JUnit are returned in a specific order.
We have a quite a good number of JUnits(running into thousands). Many of them (don't have the exact numbers) are written in such a way that tests in a JUnit are dependent on each other. No doubt this is a bad design practice but the application is quite old.
Till now we were using JDK 1.6 that maintained the order of the methods in same order as they appear in the source code. However, we need to move to JDK 1.7. But JDK 1.7 doesn't guarantee any ordering in which the methods are returned. This results in failure of the JUnits that have dependency.
Using the suite method to maintain the order is not suitable as that would mean modifying all the JUnits.
I think JUnit 3 uses reflection to find test methods and according to the Java 7 API of class Class declared methods are NOT returned in any particular order. So it probably depends on the vendor and version of your JDK but it's surely no portable solution to expect JUnit to find the methods in sorted order.
But I must admit I'm more familiar with TestNG. TestNG offers you a way to describe dependencies between test methods via annotations. Would it be possible to upgrade the tests to use TestNG? Of course that would also mean to modify all tests as with the suite() method.
Unfortunately I can't imagine an easier way. I guess that's the price you have to pay for using dependent tests (a bad idea in my opinion). Maybe someone else can come up with a better idea.
Jeanne, as I wrote I don't like the idea of dependent tests either. I just suggested to use TestNG because it at least allows you to make the dependencies between tests explicit so you don't have to rely on the implementation details of a specific JDK.
Of course I'd recommend to remove the dependencies in tests completely as a clean solution, even if it requires more work.