AFAICT, there's not much difference between using cucumber-glue
scope and instantiating member variables in step classes other than where the instantiation code resides.
For example, using cucumber-glue
scope:
@Configuration
public class MyConfiguration {
@Bean
@Scope("cucumber-glue")
public MyContext myContext() {
return new MyContext();
}
}
@SpringBootTest
public class MySteps {
@Autowired
private MyContext myContext;
}
versus member variables:
@SpringBootTest
public class MySteps {
private final MyContext myContext = new MyContext();
}
Are there other differences I'm missing?
When you have more then one one definition file you'll want to share some information between them. You can do this by writing to the same component.
However all regular components are singleton scoped and survive between Scenarios. This makes them unsuitable for sharing test state. It might interfere with the next scenario. Fortunately cucumber-glue
scoped components (including step definitions) are recycled between scenarios. This ensures your glue code will will always be fresh.