How to read data from external file in cucumber instead of mentioning huge data's in example section? I am using Cucumber-jvm

Susanta Adhikary picture Susanta Adhikary · Aug 14, 2015 · Viewed 15.5k times · Source
@@file_name Feature: Addition

In order to avoid silly mistakes As a math idiot I want to be told the sum of two numbers

Scenario: Add two numbers

Given I have entered @number1 into the calculator
And I have entered @number2 into the calculator
When I press Add
Then the result should be @total1 on the screen

Scenarion: Multiplication After Addition

Given the total is @total1
When multiply it with @number3
Then the result should be @total2 on the screen

I have a xls file which have colums like total1 total 2, number 1, number 2 , number 3 etc..

Answer

Vincent F picture Vincent F · Aug 23, 2015

It's often tempting to do like this and refer to external file for data, however, you will totally loose the communication between stakeholders aspect of BDD by doing so.

If it's really as simple as adding 2 number like this, you can use Scenario outline / examples : https://github.com/cucumber/cucumber/wiki/Scenario-Outlines.

Otherwise, ask yourself what you're trying to achieve with Cucumber here, because I'm not sure it's worth adding this layer if it's to hide the examples in an Excel file. I would suggest you select one example that you implement in a proper scenario. For the other examples, write a regular Junit test to read from the file and get the data from it and run your code under test the same way you do from your step definition