Reputation: 15
So I want to test a input field of my application, for which I have the step `Given My list is "A,B,C". I am having a hard time deciding what to do with an empty list or a list that is too long.
Regarding an empty list, I see three options:
Given My list is ""
Given My list is "empty"
Given My list is empty
1 reuses the step implementation but does not look nice regarding readability and natural language. 2 also reuses the previous, but now I have to add a conditional if input_list == "empty": input_list = ""
to the step impl. 3 is clear in the feature file, but now needs an additional step impl.
The same problems occurs with a list that is too long:
Given My list is "A,B,C,D,...(over 100 characters)"
Given My list is "too_long"
Given My list is too long
Are there any guidlines on when you should or shouldn't reuse your steps?
Upvotes: 0
Views: 24
Reputation: 12059
I think you're overthinking it. Code reuse is great for code that does the same thing and changes together.
But natural language isn't programming and the code involved does different things. So the way you said it naturally is a good way to write it down:
I am having a hard time deciding what to do with an empty list or a list that is too long.
So good steps would be:
Given an empty list
Given a list that is too long (over 100 characters)
And then in the implementation you figure out what that means programmatically. For the second step that could be some code that generates 101 random characters I suppose.
Upvotes: 0