Skip to content

Q-PERIOR/QP_ABAP_Unit-Testing

Repository files navigation

QP_ABAP_Unit-Testing

ABAP Unit-Testing integrated on Azure DevOps.


Motivation and Basics

The key motivation is to automate ABAP Unit-Testing. This is realized by running respective ABAP Unit-Tests via Azure DevOps Pipelines.

A S/4HANA package containing Unit-Testing classes is called by an HTTP POST-request in a Node.js-App.
The respective Node.js-App is pushed into a GitHub repository.
An Azure DevOps Pipeline is placed on the GitHub repository.

Hence, we can call the Unit-Tests by running the Node.js-App through running an Azure DevOps Pipeline.
By using Azure DevOps, test results can be displayed as expressive graphics.


Application and Capabilities

ABAP Unit-Testing is run by a Node.js-APP, which can later be integrated in an Azure DevOps Pipeline, so that commits in the underlying GitHub repository automatically trigger and initiate the Node.js-APP and thereby run ABAP Unit-Testing.

Node.js-App:

The Node.js-App consists of an index.js-file, a Config-file, a XML-file and a XSL-file.

index.js-file:

To run the ABAP Unit-Tests we need to get a CSRF-Token in the first place, which is done via an HTTP GET-request.
This CSRF-Token is then included in the HTTP POST-request to run the ABAP Unit-Tests. In the same POST-request we incorporate our XML-file as body.
Using an XSL-file, we then generate JUnit test results from AUnit test results. These JUnit test results are stored in a new XML-file.
The JUnit format of the test results enables us to create expressive test result graphics later on through the Azure DevOps Pipeline.

As usual our index.js-file can be called via npm start. As variables, S4H-User and S4H-Password are required for authorization purposes of the HTTP requests, an ABAP S4H packages is required as package which consists the testing class, a path and file-name can be optionally added for storing test results. The URLs for our HTTP requests are manually inserted in the Config-File.

npm start -- --username=<S4H-User> --password=<S4H-Password> --package=<Z2607_AZURE_UNIT_TEST> --file=<result/abapResultFile.xml>

Config-file:

Besides defining a structure to carry the specified command line variables, the Config-file serves as destination to manually insert the URLs used in our HTTP requests.

XML-file:

The XML-file, which is used as body in the ABAP Unit-Testing POST-request, includes a call to run ABAP Unit-Tests contained in the package the user specifies in the command line.

XSL-file:

The XSL-file, contained in the same xml-Folder as the XML-file, is used to transform the ABAP Unit-Testing results from AUnit to JUnit format.

Azure DevOps Pipeline:

The just explained Node.js-App is pushed into a GitHub repository, upon we place an Azure DevOps Pipeline. Consequently we can run our Node.js-App through our Pipeline. This is our main goal, as we want to be able to run ABAP Unit-Tests automatically, which is now possible, as our Pipeline can be automatically initiated by commits into the underlying GitHub repository.
We integrate our Node.js-App in the yml-Pipeline-File as follows:

- script: |
    npm install
  displayName: 'npm install'

- script: |
    npm start -- --username=$(username) --password=$(password) --package=$(package) --file=$(file)
  displayName: 'ABAP Unit-Testing'

The variables username, password, package and file can be defined in Azure DevOps.
By selecting the pipeline task "Publish Test Results" in Azure DevOps, we can now integrate a task into our pipeline which publishes JUnit test results as graphics.

Releases

No releases published

Packages

No packages published