CAP full-stack testing with BDD flavour
2023-10-11 02:4:49 Author: blogs.sap.com(查看原文) 阅读量:5 收藏

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 “Cucumber”?

https://cucumber.io/
“Cucumber” is a tool that is used to validate features of software systems.
It empowers BDD as a development life-cycle. The collaborators write specifications in human-readable format using the Gherkin language (Given-When-Then) while describing how the system behaves.
The “Cucumber” module can understand the specifications and evaluate them just like tests that are validating the system features.

Steps library cds-cucumber

https://cap-js-community.github.io/cds-cucumber/
CAP provides a 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: API

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 i -g @sap/cds-dk
cds init --add sample bookshop
cd bookshop
  • install and configure the CAP cds-cucumber library
npm i -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 provides features like syntax highlighting, auto-completion
  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.


文章来源: https://blogs.sap.com/2023/10/10/cap-full-stack-testing-with-bdd-flavour/
如有侵权请联系:admin#unsafe.sh