3.7. Step - 05 : Tabulated entries¶
Now let’s add tests with a table of entries:
# For repeated parameters,
# we can use table
Feature: Tabulated maths
Scenario Outline: Addition from a table
Given I have '<num1>' and '<num2>'
When I add them
Then The result must be '<total>'
Examples:
| num1 | num2 | total |
| 1 | 2 | 3 |
| 10 | 20 | 30 |
| 22 | 33 | 55 |
| 22 | 33 | 55 |
Now, the file/folder structure looks like this:
.
|-- features
| |-- steps
| | `-- steps_addition.py
| |-- environment.py
| |-- simple-addition.feature
| `-- table-addition.feature
`-- libmath.py
With above contents, if we run behave:
behave --no-timings --no-source
We can see more tests are added… and everything is successful:
Feature: Simple Addition
Showcase simple addition for the BDD Book.
Scenario: Addition of single digit numbers
Given I have '1' and '3'
When I add them
Then The result must be '4'
Scenario: Addition of double digit numbers
Given I have '70' and '29'
When I add them
Then The result must be '99'
Feature: Tabulated maths
Scenario Outline: Addition from a table -- @1.1
Given I have '1' and '2'
When I add them
Then The result must be '3'
Scenario Outline: Addition from a table -- @1.2
Given I have '10' and '20'
When I add them
Then The result must be '30'
Scenario Outline: Addition from a table -- @1.3
Given I have '22' and '33'
When I add them
Then The result must be '55'
Scenario Outline: Addition from a table -- @1.4
Given I have '22' and '33'
When I add them
Then The result must be '55'
2 features passed, 0 failed, 0 skipped
6 scenarios passed, 0 failed, 0 skipped
18 steps passed, 0 failed, 0 skipped, 0 undefined
Took 0m0.001s
3.8. Changes¶
As compared to previous section Step - 04 : Add implementation and pass, the changes in files is:
Files old/features/environment.py and new/features/environment.py are identical
Files old/features/simple-addition.feature and new/features/simple-addition.feature are identical
Files old/features/steps/steps_addition.py and new/features/steps/steps_addition.py are identical
diff '--unified=3' --new-file --ignore-all-space --text --recursive --show-c-function --report-identical-files old/features/table-addition.feature new/features/table-addition.feature
--- old/features/table-addition.feature 1970-01-01 05:30:00.000000000 +0530
+++ new/features/table-addition.feature 2022-12-11 00:00:00.000000000 +0530
@@ -0,0 +1,16 @@
+# For repeated parameters,
+# we can use table
+
+Feature: Tabulated maths
+
+ Scenario Outline: Addition from a table
+ Given I have '<num1>' and '<num2>'
+ When I add them
+ Then The result must be '<total>'
+
+ Examples:
+ | num1 | num2 | total |
+ | 1 | 2 | 3 |
+ | 10 | 20 | 30 |
+ | 22 | 33 | 55 |
+ | 22 | 33 | 55 |
Files old/libmath.py and new/libmath.py are identical