4
@@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..

KuKeC
  • 4,392
  • 5
  • 31
  • 60
Susanta Adhikary
  • 257
  • 2
  • 6
  • 20
  • The use case I have is initializing databases before each test. We have 20+ tables with hundreds of rows. Putting all of this in the feature file seems crazy. If I use external files I can have different profiles of data and load the appropriate data set with a simple stepdef. – Christopher Helck Dec 03 '21 at 03:32

2 Answers2

2

AAARG! It seem the distinction between Data Tables (https://docs.cucumber.io/gherkin/reference/#data-tables) and Examples: tables (only ever used in conjunction with Scenario Outline) is completely lost on the people in this thread. The way you can eliminate any perceived need for an external spreadsheet is with the data table being right in the feature file. In that way, there no external dependencies that will create maintenance headache down the road; it's all in the feature file, where it belongs.

bogghead
  • 37
  • 2
  • 1
    serious question...what if you have 12 million rows of data to test? – Tim Boland Feb 05 '22 at 04:09
  • I think it the "external" word got missing somewhere... like Tim Boland correctly said... if there is a 12million row data? Would you write a 12 million data table in the feature file? If the data are credit card numbers, SSN or passwords? I don't want that data exposed in the feature. So how to attach an external file like excel as the data source? – Kyon Perez Feb 09 '22 at 18:16
1

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

Vincent F
  • 6,523
  • 7
  • 37
  • 79