7

ABAP Unit-Testing via Azure DevOps Pipelines

 1 year ago
source link: https://blogs.sap.com/2023/01/20/abap-unit-testing-via-azure-devops-pipelines/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
January 20, 2023 4 minute read

ABAP Unit-Testing via Azure DevOps Pipelines

Motivation and Functionality

In this blog we want to show how ABAP Unit-Tests can be run from a CI/CD pipeline. This is relevant for all cases where an automatic deployment shall be achieved. We run the respective ABAP Unit-Tests through automatically triggered Azure DevOps pipelines. Graphically displayed test results are also desired to be obtained. In the following, I will start by explaining the rough procedure and architecture. A graphical delineation can be viewed in figure 1.

ABAP Unit-Tests belonging to an ABAP class are called by an HTTP POST-request in a Node.js-App, that executes JavaScript code. The respective ABAP package, which contains the tested ABAP classes, is pushed into a GitHub repository, on which we place an Azure DevOps pipeline. Consequently, our Azure DevOps pipeline can be triggered by commits of its underlying GitHub repository, respectively by changes of our ABAP package objects to which belong the tested ABAP classes.

Meanwhile, the respective Node.js-App is pushed into another GitHub repository. Therefor we use a different repository than the one in which we store the ABAP package. Otherwise it would be necessary that all the GitHub repositories of all the ABAP packages that shall be tested, and upon which we place Azure DevOps pipelines, contain our Node.js-App. This would be inconvenient and could eventually cause additional maintenance efforts. By cloning a particular Node.js-App repository, we avoid these issues and potential referencing complications. The Node.js-App repository is then cloned in our pipeline, so that we are able to run the Node.js-App through running our triggered Azure DevOps pipeline.

Altogether, if an ABAP class to be tested is changed and committed into its ABAP package’s GitHub repository, a connected Azure DevOps pipeline will be triggered to run, which starts a Node.js-App that calls Unit-Tests on the ABAP class and delivers JUnit-formatted test results.

Finally, a ready-to-use task in our pipeline enables us to display test results in a JUnit format as expressive graphics in Azure DevOps.

Figure%201

Figure 1

Tutorial and Guidance

Initially, we tried to take advantage of the abap_test_runner_cli, which promised to run Unit-Tests through command line inputs. This nevertheless failed to be integrated in our Azure DevOps pipeline. For further information regarding the abap_test_runner_cli, see Jakob Marius Kjær’s  blog article.

We then switched to Mattias Johansson’s Node.js-App, to which we aligned when implementing our Unit-Test-running Node.js-App. Detailed explanations of the code and of the functionality of the Node.js-App can be found in Mattias Johansson’s respective blog article.

Basically, our Node.js-App first calls an HTTP GET-request to fetch a CSRF-Token needed to run ABAP Unit-Tests. This CSRF-Token is then included in the HTTP POST-request to run the ABAP Unit-Tests. Thereby, a XML-file, which includes a call to run ABAP Unit-Tests, is used as body. The ABAP Unit-Testing results are then transformed from AUnit to JUnit format by using a XSL-file.

When starting the Node.js-App, SAP-username, SAP-password, the ABAP-Package containing the ABAP classes to be tested, and the path of the file for test-results have to be specified by the user, for example as follows:

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

The target file is thereby optional. If not specified, a default file will be chosen. This target file contains the XML-formatted test results of our ABAP Unit-Tests.

Now, the ABAP package which contains the ABAP classes to be tested, and the Unit-Testing Node.js-App should be integrated into an Azure DevOps pipeline. Therefore, we first push the respective ABAP package in a GitHub repository. This GitHub repository is then used to build an Azure DevOps pipeline, so that a commit in this ABAP package repository can be used as pipeline trigger.

Figure 2 shows in line 6 that our pipeline is triggered by commits of the underlying GitHub repository’s main branch. Further on, Node.js has to be installed.

Figure%202

Figure 2

As seen in figure 3, we then clone a second GitHub repository, which consists of our Node.js-App.

Figure%203

Figure 3

The cloned GitHub repository is stored in a working dictionary which has the same name as the GitHub repository. In this working directory, we then execute the npm install command, and later on the npm start command with specified variables – as shown in figure 4.

Figure%204

Figure 4

As explained before, our Node.js-App stores a file with JUnit formatted test results in a dictionary which can be specified. Figure 5 shows that a ready-to-use DevOps task can be included in the pipeline which publishes JUnit formatted test results as graphics.

Figure%205

Figure 5

In figure 6 and figure 7 you can see samples of these expressive test result graphics.

Figure%206

Figure 6

Figure%207

Figure 7

Conclusion

Summed up, we can conclude that automating ABAP Unit-Testing successfully works by applying the mentioned Node.js-App and integrating the App into a pipeline build on the ABAP package that contains the ABAP classes to be tested.

Continuous Integration of ABAP Unit-Testing provides the benefit of automatically triggering Unit-Testing while working on ABAP packages. This definitely saves time and effort.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK