Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
vLeonkev
Product and Topic Expert
Product and Topic Expert
969

Quality of services demonstrates commitment, leads to customer satisfaction and builds trust.
Harmonious and intuitive designed product plays a crucial role in ensuring a positive customer experience.
In this blog, we're going to unpack a promising method that might assist us in accomplishing our goal.


Before presenting the CAP's contribution, let's start by giving a quick introduction to the involved components and technologies.



CAP


https://cap.cloud.sap/docs/
CAP applications consists of CDS model, service with database access and UI (graphical user interface).
A CAP service can support several protocols like OData, Rest, GraphQL.
The UI can use any framework that works with any of the mentioned service protocols.
SAP UI5 with SAP Fiori® Elements is first class citizen as it is well integrated with the CDS model and supports several paradigms offered by CAP.



What is BDD?


BDD stands for Behavior-Driven Development and is a software development process encouraging collaboration between customers, software architects, software developers, quality assurance experts and information developers. The final outcome of the collaboration consists of specifications presented in a human-readable format utilizing the Gherkin language. The specifications will be used to validate the correct implementation of the features. Here is an example specification:
Feature: Bookshop first feature file

Scenario: Open "Manage Books" as "alice" and search for "jane"
Given we have started the CAP application
And we have opened the url "/" with user "alice"
When we select tile "Manage Books"
And we search for "jane"
Then we expect to have 2 table records

What is "Cucumber"?


https://cucumber.io/
"Cucumber" is a tool that is used to validate features of software systems and it empowers BDD as a development life-cycle.
The "Cucumber" module can understand the specifications and evaluate them just like tests that are validating the system features.
In order to evaluate the specifications "Cucumber" requires step definitions written in any of the supported programming language.



Step definitions library cds-cucumber


https://cap-js-community.github.io/cds-cucumber/
CAP provides a Nodejs library with ready-to-use steps for writing specifications utilizing the "cucumber" module.
The cds-cucumber library covers SAP Fiori® Elements and in addition the OData protocol.
It is deeply integrated with CAP providing Service-Lifecycle-Management like: process initialization, port assigning, directory management, browser control, authentication. The OData part has knowledge of the service names, entities and fields as it works directly with the CDS model.
The documentation of all steps with short examples is available under the following link: step definitions.



Using the cds-cucumber module


https://cap-js-community.github.io/cds-cucumber/#usage




  • In case you do not have already a CAP application, install cds-dk and create a sample application



npm add -g @sap/cds-dk
cds init --add sample bookshop
cd bookshop



  • install and configure the CAP cds-cucumber library



npm add -D @cap-js-community/cds-cucumber
npx cds-add-cucumber



  • write specifications or use the already generated ones contained in the samples CAP app
    File: test/features/first.feature



Feature: Bookshop first feature file

Scenario: Open "Manage Books" as "alice" and search for "jane"
Given we have started the CAP application
And we have opened the url "/" with user "alice"
When we select tile "Manage Books"
And we search for "jane"
Then we expect to have 2 table records



  • run the tests



npx cucumber-js test

VSCode integration


The Visual Studio Code Editor, in conjunction with its plugins, delivers effortless integration and robust support for cucumber, enabling you to optimize your workflow when authoring your specifications. Here are some further details about it:




  1. standard VSCode cucumber plugin provides features like syntax highlighting, autocompletion

  2. debugging CDS Node.js runtime code as described here

  3. debugging browser code in VSCode as described here


Wrapping it up


The module is provided as open-source. It is freely accessible and active participation is highly appreciated. Furthermore, the repository includes tests for popular sample projects, showcasing the elegance and flexibility of the solution.