I understand from Techtalk that coupling step definitions to features is an anti-pattern. However I am wondering how to organise my step definitions so that I can easily see in the code what steps go together.
For example should I create a code file for each Feature and a separate file for steps that are shared? or should I have a code file for a set of features?
We recommend arranging step definitions by domain concept or system interface, while arranging feature files by business functionality. This is more cohesive than arranging by feature, since the body of step definitions face towards the application itself and allows things to change naturally over time.
Right-click on any step of the Feature File, then click on Generate Step Definitions option. In the Generate Step Definition Skeleton pop-up, check the steps for which we want to generate the implementation. Add a Class Name, then click on the Generate button.
I tend to organize step definitions in a couple of ways, depending on how big the step definition files get.
Separate data and UI steps
I have lots of Given some thing exists in the database
steps, so I usually throw these into a file call DataSteps.cs. I also have lots of Then something exists in the database
steps and those go into DataAssertionSteps.cs.
All of my When I fill in some form field
steps go in FormSteps.cs. Anytime I need Then something in the form is enabled|disabled
or asserting that form fields have a certain value, I throw those into FormPresentationSteps.cs.
Separate Steps by Model
Sometimes my step definition files get very large, and I start moving step definitions into files related to a certain model. Say I have a Person
model. I might create a PersonSteps.cs file that is split into three regions:
[Binding]
public class PersonSteps
{
#region Given
// Given a person exists with the following attributes:
#endregion
#region When
// When something something about a Person
#endregion
#region Then
// Then a person should exist with the following attributes:
#endregion
}
Basically I start out with these files:
Given
s for setting up test dataThen
s for asserting that data exists correctly in the databaseIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With