junit-team / junit4

A programmer-oriented testing framework for Java.
https://junit.org/junit4
Eclipse Public License 1.0
8.51k stars 3.24k forks source link

@Rule execution order looks to have been guaranteed since 4.12 but is not documented as such #1725

Open cpovirk opened 2 years ago

cpovirk commented 2 years ago

My understanding is that https://github.com/junit-team/junit4/commit/c75dcc28810aeb1c918ee7430981b31f41742ea7#diff-f35409420f2540415a9878beaf5a537248f301b6c683bb87a11016be3c9dc8b8R55 caused JUnit to begin processing @Rule fields in a defined order. The @Rule Javadoc, however, still states that the order is defined by the JVM's reflection API.

It would be good to know whether the intent is to commit to this order or not. I suppose that the current doc is technically wrong either way, since the current order is not dependent on the JVM reflection API :) But mainly I want to know how safe this is to rely on. Thanks.

(Sorry if I missed some past discussion in my searching or if I've misunderstood something.)

panchenko commented 2 years ago

Since 4.13 the recommended way is using the order attribute of the @Rule annotation. It's described in the Ordering section in bottom of the javadoc. The sentence you linked is quite old and potentially needs an update :-)