PicoContainer injection in @BeforeAll and @AfterAll hooks #2279
-
|
Hello. I was excited to try the The annotations insist they should be on static methods, but the test actions I want to do really need some objects injected from the PicoContainer. It seems the glue class I made for the hooks doesn't get instantiated at all. I've tried moving them from constructor injection to annotated static fields, but they don't seem to be getting injected. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
|
Dependency injection with Pico container is scoped to the scenarios life cycle. This ensures that state is not accidentally shared between scenarios. But without an active scenario there is also no dependency injection context to inject from. This is something I've been wanting to improve for a while now but there are other problems to solve first. Now you didn't mention what your concrete problem is, but here are some options:
|
Beta Was this translation helpful? Give feedback.
Dependency injection with Pico container is scoped to the scenarios life cycle. This ensures that state is not accidentally shared between scenarios. But without an active scenario there is also no dependency injection context to inject from. This is something I've been wanting to improve for a while now but there are other problems to solve first.
Now you didn't mention what your concrete problem is, but here are some options:
@Beforehook and implement the exactly once semantics yourself.cucumber-springand create a@Componentwith a@EventListener(ContextStartedEvent.class)annotated method. This will allow you to access the application scoped beans and do any additio…