How to share the Spring Boot context between steps in cucumber test?
I am working on a cucumber integration test project for spring boot. Currently I have only one feature file, and I have placed @SpringBootTest & @AutoConfigureMockMvc annotations within the stepdef file. I would like to have these annotations common for all step files. Please help me in doing this. I would much appreciate any help. Thanks.
If you are using the latest Cucumber (v5.7.0) to make Cucumber aware of your test configuration you can annotate a configuration class on your glue path with `@CucumberContextConfiguration` and with one of the following annotations: `@ContextConfiguration`, `@ContextHierarchy` or `@BootstrapWith`. If you are using SpringBoot, you can annotate configuration class with `@SpringBootTest`
You can then `@Autowire` components from the application context into any step definition file. No further spring configuration is needed. For example:
@Given("feed back is requested from my service")
The only requirement is that both `MyStepDefinitions` and `CucumberSpringConfiguration` are both in a package that is on the glue path. So either you have configured `@CucumberOptions(glue="com.example")` explicitly or your test runner class is in the same package as your step definition (`com.example`).