Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Your specification is made using Gherkin (i.e. Given, When, That) statements in Scenario(s) or Scenario Outline(s), eventually complemented with a Background. Implementation of each Gherkin statement (i.e. "step") is done in code; the Cucumber framework finds the code based on regular or cucumber expressions.


Note
iconfalse
titleSource-code for this tutorial
typeInfo

Code is available in GiHub; the repo contains some auxiliary scripts.

Usage scenarios

Cucumber is used in diverse scenarios. Next you may find some usage patterns, even though Cucumber usage is mostly recommended only if you are adopting BDD.

...

After being exported, the created .feature(s) will contain references to the Test issue key, eventually prefixed (e.g. "TEST_") depending on an Xray global setting, and the covered "requirement" issue key,  if that's the case. The naming of these files is detailed in Export Generate Cucumber Features.

Code Block
titlefeatures/2_CALC-640.feature
collapsetrue
@REQ_CALC-640
Feature: As a user, I can calculate the sum of 2 numbers
	#As a user, I can calculate the sum of 2 numbers

	#simple integer addition
	@TEST_CALC-642
	Scenario: simple integer addition
		Given I have entered 1 into the calculator
		And I have entered 2 into the calculator
		When I press add
		Then the result should be 3 on the screen

	#negative integer addition
	@TEST_CALC-643
	Scenario: negative integer addition
		Given I have entered -1 into the calculator
		And I have entered 2 into the calculator
		When I press add
		Then the result should be 1 on the screen

	#sum of two positive numbers
	@TEST_CALC-644
	Scenario Outline: sum of two positive numbers
		Given I have entered <input_1> into the calculator
		And I have entered <input_2> into the calculator
		When I press <button>
		Then the result should be <output> on the screen
		
		  Examples:
		    | input_1 | input_2 | button | output |
		    | 20      | 30      | add    | 50     |
		    | 2       | 5       | add    | 7      |
		    | 0       | 40      | add    | 40     |
		    | 4       | 50      | add    | 54     |
		    | 5       | 50      | add    | 55     |

...

After being exported, the created .feature(s) will contain references to the Test issue key, eventually prefixed (e.g. "TEST_") depending on an Xray global setting, and the covered "requirement" issue key,  if that's the case. The naming of these files is detailed in Export Generate Cucumber Features.

Code Block
titlefeatures/2_CALC-640.feature
collapsetrue
@REQ_CALC-640
Feature: As a user, I can calculate the sum of 2 numbers
	#As a user, I can calculate the sum of 2 numbers

	#simple integer addition
	@TEST_CALC-642
	Scenario: simple integer addition
		Given I have entered 1 into the calculator
		And I have entered 2 into the calculator
		When I press add
		Then the result should be 3 on the screen

	#negative integer addition
	@TEST_CALC-643
	Scenario: negative integer addition
		Given I have entered -1 into the calculator
		And I have entered 2 into the calculator
		When I press add
		Then the result should be 1 on the screen

	#sum of two positive numbers
	@TEST_CALC-644
	Scenario Outline: sum of two positive numbers
		Given I have entered <input_1> into the calculator
		And I have entered <input_2> into the calculator
		When I press <button>
		Then the result should be <output> on the screen
		
		  Examples:
		    | input_1 | input_2 | button | output |
		    | 20      | 30      | add    | 50     |
		    | 2       | 5       | add    | 7      |
		    | 0       | 40      | add    | 40     |
		    | 4       | 50      | add    | 54     |
		    | 5       | 50      | add    | 55     |

...