Execution Order for JUnit Tests #2948
-
Hey Im just really curious, why order the JUnit tests execution by hashing the names and ordering that way? Why not just start at the top of the file and work your way down? Could someone just explain this decision? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
JUnit introspects the methods of a compiled test class using Java's reflection APIs. JUnit is not aware of the source code of test classes. The JDK does not provide any API that allows one to infer the order in which methods are declared in the source code. The only built-in tool we have is Thus, in order to enforce consistent ordering of test methods across multiple runs of the same test suite, we implemented a mechanism that is non-obvious yet deterministic, as stated in the User Guide:
|
Beta Was this translation helpful? Give feedback.
JUnit introspects the methods of a compiled test class using Java's reflection APIs. JUnit is not aware of the source code of test classes.
The JDK does not provide any API that allows one to infer the order in which methods are declared in the source code.
The only built-in tool we have is
java.lang.Class.getDeclaredMethods()
which makes no guarantee about the ordering of the methods.Thus, in order to enforce consistent ordering of test methods across multiple runs of the same test suite, we implemented a mechanism that is non-obvious yet deterministic, as stated in the User Guide: