Undefined hook execution order across multiple glue packages in Cucumber JVM
0 reputation · 17 Dec 2020, 02:08 UTC
Cucumber JVM (7.x) scans every glue package for classes containing @Before and @After methods and registers all hooks it finds. The documentation states that execution order is undefined unless an explicit order is given. In a project that keeps scenario setup and teardown logic in several glue packages — for example, one package for database fixtures and another for application state — the sequence in which hooks run is not guaranteed to be stable across builds, after a new package is added, or under parallel execution where each runner may resolve glue classes independently.
The goal is a repeatable development environment in which hook execution is deterministic without forcing every hook class into a single package. Constraints: versions before 7.0 may resolve glue classes through a different scanning mechanism, so any ordering convention must be validated against the version in use; classloader registration order is not a safe basis for sequencing.
- What is the documented mechanism in Cucumber JVM 7.x for assigning a deterministic order to
@Beforeand@Afterhooks that live in different glue packages? - Does explicit ordering also hold under parallel execution, or are there additional caveats for concurrent runners?
- How should cleanup hooks that must run last be expressed so the ordering stays maintainable as glue packages evolve?