From: Mark U. <ma...@cs...> - 2013-04-10 00:03:57
|
Anthony and Andrius, On 10 April 2013 03:18, Anthony Hall <an...@an...> wrote: > Dear Andrius**** > > * * > > That is an interesting observation! I am reading myself online now that > JUnit does run tests in an arbitrary order.. I did have the same assumption > as you.**** > > Bizarre, isn’t it? I particularly like the doctrinaire ignorance of “of > course your tests should be totally independent” – what world do these > people live in? > Actually, it is probably caused by Java 1.7 -- since build 129 of Java SE the reflection method getMethods() returns the methods in a non-deterministic order. (Before that, it returned them in source code order). So if you've upgraded to Java 1.7, JUnit has no way of knowing the original order of the methods any more. Sun says this is a feature, not a bug. And http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7023180 says: Filed a request for JUnit to behave predictably irrespective of VM order: https://github.com/KentBeck/junit/pull/293 2011-09-09 I don't know if this has been implemented in JUnit yet. I doubt it. (Presumably they would have to parse the source code of your Java). I think relying on the order of test methods is bad style anyway, because it makes it hard to tools to run tests in isolation, means that test suite minimisation algorithms do not work, you cannot automatically reorder tests to run the quick ones first, etc. Cheers Mark *Area:* HotSpot *Synopsis:* Order of Methods returned by Class.get Methods can Vary *Description:* In JDK 7, build 129, the following reflective operations in java.lang.Class changed the fixed order in which they return the methods and constructors of a class: - getMethods - getDeclaredMethods - getDeclaredConstructors This may cause issues for code that assumes (contrary to the specification) a particular order for methods or constructors. |