Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to organize step definitions when using cucumber-java?

I am new to Cucumber and I am using cucumber-java. The cucumber feature files look great. However, the reuse of step definitions really gets in the way about organizing the step definition code. The most intuitive way for me to organize the step definitions is just to follow the organization of the feature files, namely, one class for one feature. However, this way is screwed if there are two identical steps in two feature files, because you will miss one step in one of the classes, which breaks the coherence of the entire structure. However, I cannot convince myself to use other ways right now. So, what is a sensible way to organize step definitions when using cucumber-java?

Thank you very much.

like image 369
JBT Avatar asked Mar 04 '14 03:03

JBT


2 Answers

Start with the way you are already doing and once you recognize that a step is reused, move it a class ReUsableSteps or something. This way, if a step does not exist in its class then it should be in ReUsableSteps. Just a thought.

like image 105
Bala Avatar answered Sep 27 '22 21:09

Bala


You can have a separate package as placeholder for classes that defines common steps. Add that package as glue.

like image 30
user861594 Avatar answered Sep 27 '22 21:09

user861594