4.4. Step - 02 : Add feature files¶
Now, let’s add Feature/Scenario file. This is very similar to BDD - Python / Step - 01 : Initial structure
The updated directory structure would be like this:
.
|-- features
| |-- step_definitions
| | `-- steps_addition.cpp
| |-- CMakeLists.txt
| `-- simple-addition.feature
`-- CMakeLists.txt
features/simple-addition.feature
This new file has the Feature/Scenario steps for the BDD Tests.
# features/sample-addition.feature 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'
features/CMakeLists.txt
We update
features/CMakeLists.txt
to also include*.feature
files. This is totally optional, but in cases where we use CMake to generate IDEs files, these*.feature
would be part of the IDE and it would help edit those files directly from the IDE.PROJECT(features) FILE( GLOB all_files step_definitions/*.cpp step_definitions/*.hpp *.feature ) ADD_EXECUTABLE(${PROJECT_NAME} ${all_files}) TARGET_LINK_LIBRARIES( ${PROJECT_NAME} CucumberCpp::cucumber-cpp )
4.4.1. Changes¶
As compared to previous step (Step - 01 : Setup of C/C++ Code), the diff is:
Files old/CMakeLists.txt and new/CMakeLists.txt are identical
diff '--unified=3' --new-file --ignore-all-space --text --recursive --show-c-function --report-identical-files old/features/CMakeLists.txt new/features/CMakeLists.txt
--- old/features/CMakeLists.txt 2022-12-11 00:00:00.000000000 +0530
+++ new/features/CMakeLists.txt 2022-12-11 00:00:00.000000000 +0530
@@ -5,6 +5,7 @@ FILE(
all_files
step_definitions/*.cpp
step_definitions/*.hpp
+ *.feature
)
ADD_EXECUTABLE(${PROJECT_NAME} ${all_files})
diff '--unified=3' --new-file --ignore-all-space --text --recursive --show-c-function --report-identical-files old/features/simple-addition.feature new/features/simple-addition.feature
--- old/features/simple-addition.feature 1970-01-01 05:30:00.000000000 +0530
+++ new/features/simple-addition.feature 2022-12-11 00:00:00.000000000 +0530
@@ -0,0 +1,16 @@
+# features/sample-addition.feature
+
+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'
+
Files old/features/step_definitions/steps_addition.cpp and new/features/step_definitions/steps_addition.cpp are identical