4.6. Step - 04 : Add Dummy Steps

Now, let’s add dummy steps to steps_addition.cpp File.

The updated directory structure would be like this:

.
|-- features
|   |-- step_definitions
|   |   |-- cucumber.wire
|   |   `-- steps_addition.cpp
|   |-- CMakeLists.txt
|   `-- simple-addition.feature
`-- CMakeLists.txt
  • features/step_definitions/steps_addition.cpp

    This file just has almost empty steps with pending().

    Note

    We could have use regular expressions to re-use the steps, but we will do that later in Step - 07 : Use regular expressions for tests. Right now, just taking a short-cut to keep things moving.

    #include <gtest/gtest.h>
    #include <cucumber-cpp/autodetect.hpp>
    
    // We could have used Regular Expressions here
    // to reduce the duplicated steps.
    // but we will introduce that concept later.
    
    GIVEN("^I have '1' and '3'$") {
        pending();
    }
    
    GIVEN("^I have '70' and '29'$") {
        pending();
    }
    
    WHEN("^I add them$") {
        pending();
    }
    
    THEN("^The result must be '4'$") {
        pending();
    }
    
    THEN("^The result must be '99'$") {
        pending();
    }
    

4.6.1. Changes

As compared to previous step (Step - 03 : Run tests with Wire and Cucumber), the diff is:

Files old/CMakeLists.txt and new/CMakeLists.txt are identical
Files old/features/CMakeLists.txt and new/features/CMakeLists.txt are identical
Files old/features/simple-addition.feature and new/features/simple-addition.feature are identical
Files old/features/step_definitions/cucumber.wire and new/features/step_definitions/cucumber.wire are identical
diff '--unified=3' --new-file --ignore-all-space --text --recursive --show-c-function --report-identical-files old/features/step_definitions/steps_addition.cpp new/features/step_definitions/steps_addition.cpp
--- old/features/step_definitions/steps_addition.cpp	2022-12-11 00:00:00.000000000 +0530
+++ new/features/step_definitions/steps_addition.cpp	2022-12-11 00:00:00.000000000 +0530
@@ -1,3 +1,27 @@
-// features/step_definitions/steps_addition.cpp
-//
-// Just an Empty CPP File to allow compilation.
+
+#include <gtest/gtest.h>
+#include <cucumber-cpp/autodetect.hpp>
+
+// We could have used Regular Expressions here
+// to reduce the duplicated steps.
+// but we will introduce that concept later.
+
+GIVEN("^I have '1' and '3'$") {
+    pending();
+}
+
+GIVEN("^I have '70' and '29'$") {
+    pending();
+}
+
+WHEN("^I add them$") {
+    pending();
+}
+
+THEN("^The result must be '4'$") {
+    pending();
+}
+
+THEN("^The result must be '99'$") {
+    pending();
+}

4.6.2. Pre-Compile

As mentioned in Step - 01 : Setup of C/C++ Code, please ensure you run CMake so that workspace is created, and run make all so that feature executable is compiled.

4.6.3. Running feature executable

As a first step, we need to run the feature executable in background.

./features/features -v &

If everything is setup perfectly, the output looks like this:

Listening on 127.0.0.1:3902

4.6.4. Running cucumber

Now let’s run Cucumber.

cucumber

The output is as follows. So far, with what ever we have done, this is as expected. We have not setup any steps and hence cucumber gives too many warnings (and helper snippets as well).

*** THIS RUBY IMPLEMENTATION DOESN'T REPORT FILE AND LINE FOR PROCS ***
# features/sample-addition.feature
Feature: Simple Addition
  
    Showcase simple addition for the BDD Book.

  Scenario: Addition of single digit numbers # features/simple-addition.feature:7
    Given I have '1' and '3'                 # steps_addition.cpp:9
       (Cucumber::Pending)
      features/simple-addition.feature:8:in `Given I have '1' and '3''
    When I add them                          # steps_addition.cpp:17
    Then The result must be '4'              # steps_addition.cpp:21

  Scenario: Addition of double digit numbers # features/simple-addition.feature:12
    Given I have '70' and '29'               # steps_addition.cpp:13
       (Cucumber::Pending)
      features/simple-addition.feature:13:in `Given I have '70' and '29''
    When I add them                          # steps_addition.cpp:17
    Then The result must be '99'             # steps_addition.cpp:25

2 scenarios (2 pending)
6 steps (4 skipped, 2 pending)
0m0.015s

As you can see, the output is different from Step - 03 : Run tests with Wire and Cucumber. We no longer see warning at the end of the execution that we are missing something. The warnings have moved from undefined to pending.