3.4. Step - 03 : Run with defined steps¶
Let’s define some step mapping in features/steps/steps_addition.py
as shown below:
# features/steps/steps_addition.py
from behave import given, when, then
@given(u"I have '{num1:d}' and '{num2:d}'")
def given_i_have(context, num1, num2):
raise NotImplementedError("STEP: Geven I Have")
@when(u"I add them")
def when_i_add(context):
raise NotImplementedError(u"STEP: When I add them")
@then(u"The result must be '{value:d}'")
def then_the_result_must_be(context, value):
raise NotImplementedError(u"STEP: Then The result must be")
With above contents, if we run behave:
behave --no-timings --no-source
Although tests are failing, towards the end of the console log, you can see that behave
mentions that there are there are 0 undefined steps:
features/simple-addition.feature:7 Addition of single digit numbers
features/simple-addition.feature:12 Addition of double digit numbers
0 features passed, 1 failed, 0 skipped
0 scenarios passed, 2 failed, 0 skipped
0 steps passed, 2 failed, 4 skipped, 0 undefined
Took 0m0.000s
3.4.1. Changes¶
As compared to previous section Step - 01 : Initial structure, 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
diff '--unified=3' --new-file --ignore-all-space --text --recursive --show-c-function --report-identical-files old/features/steps/steps_addition.py new/features/steps/steps_addition.py
--- old/features/steps/steps_addition.py 2022-12-11 00:00:00.000000000 +0530
+++ new/features/steps/steps_addition.py 2022-12-11 00:00:00.000000000 +0530
@@ -1,2 +1,16 @@
# features/steps/steps_addition.py
-# Empty for time being
+
+from behave import given, when, then
+
+@given(u"I have '{num1:d}' and '{num2:d}'")
+def given_i_have(context, num1, num2):
+ raise NotImplementedError("STEP: Geven I Have")
+
+@when(u"I add them")
+def when_i_add(context):
+ raise NotImplementedError(u"STEP: When I add them")
+
+@then(u"The result must be '{value:d}'")
+def then_the_result_must_be(context, value):
+ raise NotImplementedError(u"STEP: Then The result must be")
+
Files old/libmath.py and new/libmath.py are identical