1

How does cucumber initialize a given step definition Java class which corresponds to a given feature file having multiple scenarios and all scenarios are sharing a Background (Given condition) to initialize a instance variable.

My Question is to know is it like one step definition Java class 's object per scenario given in feature file?

If my understanding is correct , does that impact performance of execution? Can it be improved having thread safety intact.

3
  • For each scenario, a fresh instance of step definition and hook classes are created. Also the same for each row of examples table for a scenario outline. If you want to share a variable across scenarios try making it static. If you want to reuse instances among threads you will need to take care of thread safety in step definition code. Not to mention changing how cucumber framework instantiates classes. Using a DI container may be something to look at... Feb 11, 2018 at 10:25
  • Actually, what do you want to achieve? Do you want to share some variable across scenarios or just to understand how cucumber works?
    – mbob
    Feb 12, 2018 at 9:53
  • @mbob I 'm basically thinking from the perspective if there are 100 of scenarios (or example values) in feature file then that much of objects of step definition class will be created. Each object may be a complex representation with other dependencies, resources, etc. And for a big application this can be much of bottleneck. We know we have to provide data separation among scenarios (or examples) but that is coming at this cost. Is that correct? Feb 13, 2018 at 3:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.