Data driven tests – keep your Gherkin tests DRY

By: Slav Kurochkin

Data driven tests should follow the best software development practices - DRY (Don't Repeat Yourself). BDD tools such as Cucumber or Specflow let us have this opportunity and define it on early stages of test development.

Typically what you would see is tests doing the same thing over and over, even though the only thing is changing is data variables. Ok let me be more specific here is an example:



And this is completely fine, but if we want some negative scenarios and validate output getting handled the way we expecting it to be. Then our tests would look something like this:



As you can see the only stuff been changed is data parameters. So how can we not repeat ourselves and keep our data driven tests DRY? The answer is to use Scenario Outline, it will help reduce repetitive writings and be more focused on the result outcomes.
Here is how you can reduce your data driven tests:

View Comments

Leave a Comment

Use markdown or basic HTML and be nice.