Every product feature will have a dedicated feature file. The feature file is a text file with the .feature extension. A feature file can contain any number of scenarios, and each scenario is equivalent to a test case.
Let's take a look at a simple feature file example:
1 # language: en
2
3 Feature: The Facebook application should authenticate user login.
4
5 Scenario: Successful Login
6 Given I navigate to Facebook login page https://www.facebook.com
7 And I type jegan@tektutor.org as Email
8 And I type mysecretpassword as Password
9 When I click the Login button
10 Then I expect Facebook Home Page after Successful Login
Cool, it appears like plain English, right? But trust me, this is how Cucumber test cases are written! I understand your doubt--it looks easy and cool but how does this verify the functionality, and where is the code that verifies the functionality? The cucumber-cpp framework is a cool framework, but it doesn't natively support any testing functionalities; hence cucumber-cpp depends on the gtest, CppUnit, other test frameworks. The test case implementation is written in a Steps file, which can be written in C++ using the gtest framework in our case. However, any test framework will work.
Every feature file will start with the Feature keyword followed by one or more lines of description that describe the feature briefly. In the feature file, the words Feature, Scenario, Given, And, When, and Then are all Gherkin keywords.
A feature file may contain any number of scenarios (test cases) for a feature. For instance, in our case, login is the feature, and there could be multiple login scenarios as follows:
- Success Login
- Unsuccessful Login
- Invalid password
- Invalid username
- The user attempted to login without supplying credentials.
Every line following the scenario will translate into one function in the Steps_definition.cpp source file. Basically, the cucumber-cpp framework maps the feature file steps with a corresponding function in the Steps_definition.cpp file using regular expressions.