4.8. Step - 06 : Make tests pass

Now, let’s update libMath library, and make tests pass.

  • lib/libMath.c

    With correct maths implementation.

    #include <libMath.h>
    int libMath_add(int param1, int param2) {
        return param1 + param2;

4.8.1. Changes

As compared to previous step (Step - 06 : Make tests pass), the diff is minimal. Just fix the libMath_add function:

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
Files old/features/step_definitions/steps_addition.cpp and new/features/step_definitions/steps_addition.cpp are identical
Files old/lib/CMakeLists.txt and new/lib/CMakeLists.txt are identical
diff '--unified=3' --new-file --ignore-all-space --text --recursive --show-c-function --report-identical-files old/lib/libMath.c new/lib/libMath.c
--- old/lib/libMath.c	2022-12-11 00:00:00.000000000 +0530
+++ new/lib/libMath.c	2022-12-11 00:00:00.000000000 +0530
@@ -2,5 +2,5 @@
 #include <libMath.h>
 int libMath_add(int param1, int param2) {
-    return -1; // FIXME
+    return param1 + param2;
Files old/lib/libMath.h and new/lib/libMath.h are identical

4.8.2. Pre-Compile

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

4.8.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, this process will wait for Cucumber in the background.

Listening on

4.8.4. Running cucumber

Now let’s run Cucumber.


The output is as follows.

# 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:20
    When I add them                          # steps_addition.cpp:32
    Then The result must be '4'              # steps_addition.cpp:37

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

2 scenarios (2 passed)
6 steps (6 passed)

Voila!!! All tests passed!!! One line change, and nice improvement as compared to Step - 05 : Make tests fail.