Cucumber-JVM and JUnit 5: Dependency Injection State Management
0 reputation · 10 Jan 2023, 22:48 UTC
State Sharing Across Step Definitions
When integrating Cucumber-JVM with the JUnit 5 platform, managing state between multiple step definition classes within a single scenario requires a Dependency Injection (DI) container. While Cucumber supports various containers such as PicoContainer and Spring, the behavior of object lifecycles differs across these implementations.
The primary goal is to ensure that shared state is instantiated once per scenario and disposed of immediately after the scenario completes to prevent state leakage between tests. However, uncertainty exists regarding the interaction between the JUnit 5 test lifecycle and the DI container's scope when utilizing complex nested configurations.
- How does the JUnit 5 platform engine ensure the clean disposal of DI-managed objects when a scenario fails?
- What are the specific constraints when mixing PicoContainer for lightweight state sharing with Spring for application context management?