4.5. Step - 03 : Run tests with Wire and Cucumber

As mentioned in Design of Cucumber for C/C++, the Ruby based cucumber would interact with the C/++ application. For that we need to create a cucumber.wire file. Let’s create the wire file so that we can run tests with Cucumber based on Ruby and C/C++.

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/cucumber.wire

    This new file has the values that cucumber will use to run tests.

    host: localhost
    port: 3902
    

4.5.1. Changes

As compared to previous step (Step - 02 : Add feature files), 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
diff '--unified=3' --new-file --ignore-all-space --text --recursive --show-c-function --report-identical-files old/features/step_definitions/cucumber.wire new/features/step_definitions/cucumber.wire
--- old/features/step_definitions/cucumber.wire	1970-01-01 05:30:00.000000000 +0530
+++ new/features/step_definitions/cucumber.wire	2022-12-11 00:00:00.000000000 +0530
@@ -0,0 +1,2 @@
+host: localhost
+port: 3902
Files old/features/step_definitions/steps_addition.cpp and new/features/step_definitions/steps_addition.cpp are identical

4.5.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.5.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 file would run in background and wait for connection and the output looks like this:

Listening on 127.0.0.1:3902

4.5.4. Running cucumber

Now let’s run Cucumber.

cucumber

So far, with what ever we have done, an output which shows failures is expected. We have not setup any steps and hence cucumber gives too many warnings about undefined steps (and helper snippets as well).

The output is as follows.

*** 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'                 # features/simple-addition.feature:8
    When I add them                          # features/simple-addition.feature:9
    Then The result must be '4'              # features/simple-addition.feature:10

  Scenario: Addition of double digit numbers # features/simple-addition.feature:12
    Given I have '70' and '29'               # features/simple-addition.feature:13
    When I add them                          # features/simple-addition.feature:14
    Then The result must be '99'             # features/simple-addition.feature:15

2 scenarios (2 undefined)
6 steps (6 undefined)
0m0.024s

You can implement step definitions for undefined steps with these snippets:

GIVEN("^I have '1' and '3'$") {
    pending();
}

Given(/^I have '(\d+)' and '(\d+)'$/) do |arg1, arg2|
  pending # Write code here that turns the phrase above into concrete actions
end

WHEN("^I add them$") {
    pending();
}

When(/^I add them$/) do
  pending # Write code here that turns the phrase above into concrete actions
end

THEN("^The result must be '4'$") {
    pending();
}

Then(/^The result must be '(\d+)'$/) do |arg1|
  pending # Write code here that turns the phrase above into concrete actions
end

GIVEN("^I have '70' and '29'$") {
    pending();
}

Given(/^I have '(\d+)' and '(\d+)'$/) do |arg1, arg2|
  pending # Write code here that turns the phrase above into concrete actions
end

THEN("^The result must be '99'$") {
    pending();
}

Then(/^The result must be '(\d+)'$/) do |arg1|
  pending # Write code here that turns the phrase above into concrete actions
end