Friday, 10 June 2022

SAP BTP, ABAP Environment Pipeline: Introducing ABAP Unit

So, let’s get started:

ABAP Unit in the ABAP Environment Pipeline

ABAP Unit (AUnit) is the standard tool in the ABAP world for executing unit tests and thus ensuring the functional correctness of your software.

With the communication scenario “ABAP Unit Test Integration”, a service was introduced that enables the execution of ABAP Unit Tests via HTTPS. Of course, we implemented this API in our “ABAP Environment Pipeline”, so you can use it in your CI/CD processes. The newly created AUnit stage runs in parallel to the ATC stage:

SAP BTP, ABAP Development, ABAP Environment, SAP ABAP Exam Prep, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Preparation, SAP ABAP Exam Prep, SAP ABAP Certification, SAP ABAP Tutorial and Materials, SAP ABAP News
Screenshot of the pipeline stages taken from the Blue Ocean view of Jenkins

What you gain from this stage is a result file which contains the findings of ABAP Unit in the JUnit XML format. This was chosen, so you can utilize available JUnit plugins of – for example – Jenkins. In the following picture, you can see the test results on a Jenkins server with all the necessary details to analyze a failed test, including the “Error Details” and the “Stack Trace”.

SAP BTP, ABAP Development, ABAP Environment, SAP ABAP Exam Prep, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Preparation, SAP ABAP Exam Prep, SAP ABAP Certification, SAP ABAP Tutorial and Materials, SAP ABAP News
Screenshot of a test result overview generated by the JUnit plugin in Jenkins

The responsible JUnit plugin also creates a “Trend” diagram that lets you see the number of failed, skipped and passed tests of past Jenkins jobs:

SAP BTP, ABAP Development, ABAP Environment, SAP ABAP Exam Prep, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Preparation, SAP ABAP Exam Prep, SAP ABAP Certification, SAP ABAP Tutorial and Materials, SAP ABAP News
Screenshot of a diagram generated by the JUnit plugin in Jenkins

So overall, you get a nice representation of the results of ABAP Unit runs. After looking at the results of the ABAP Unit stage, let’s have a look how you need to configure it. Of course, you must specify which objects (e.g. packages or software components) should be checked. And there are two options to do this.

The first option is: you create a configuration file. Here is an example:

title: My AUnit Run
context: abapEnvironmentPipeline
options:
  scope:
    ownTests: true
    foreignTests: true
  riskLevel:
    harmless: true
    dangerous: true
    critical: true
  duration:
    short: true
    medium: true
    long: true
objectSet:
  softwarecomponents:
  - name: /DMO/SWC
  - name: /DMO/REPO

You can fill out “title” and “context” according to your own preference. The “options” allow a more detailed configuration.

◉ You can specify the “scope” – most notably, you can execute tests via “test relations” with the option “foreignTests”

◉ You can limit the “risk level” to specific values

◉ You can limit the “duration” to specific values

The “options” are, however, optional and the values default to “true” if not specified. Finally, you need to define the “objectSet”. Here, you can list either packages or software components. If you want to know all the details, please have a look at the documentation of the AUnit API. With that, the first option: you create a configuration file, is covered.

The second option is: you don’t

And this ties directly into the next section.

Pipeline Configuration


With yet another configuration file, the initial setup of the abapEnvironmentPipeline became more and more complicated. Therefore, we decided to make those configuration files for ATC, AUnit and the required service keys optional. With this step, only three mandatory files remain: the “Jenkinsfile”, the technical configuration file “.pipeline/config.yml” and the “repositories.yml” (or “addon.yml”), where you define your software components / repositories. With the latter, the pipeline generates a default configuration for AUnit and ATC. Sure, if you need to configure one of the tools in more detail, setting up dedicated configuration files is the way to go.

A minimal configuration looks like this (taken from this sample repository):

repositories.yml
repositories:
  - name: '/DMO/SWC'
    branch: 'main'

.pipeline/config.yml

general:
    cfApiEndpoint: 'https://api.cf.sap.hana.ondemand.com'
    cfOrg: 'myOrg'
    cfSpace: 'mySpace'
    cfCredentialsId: 'cfUser'
    cfServiceInstance: 'qSystem'
stages:
    Clone Repositories:
      repositories: 'repositories.yml'
      strategy: 'Pull'
    ATC:
      # In order to be executed, the ATC stage needs at least one configuration entry
      # If the ATC stage should not be executed, delete the whole section
      execute: stage
    AUnit:
      # In order to be executed, the AUnit stage needs at least one configuration entry
      # If the AUnit stage should not be executed, delete the whole section
      execute: stage

Apart from the mentioned software component / repository definition, it is only required to define the strategy for the Clone Repositories stage and to provide the connection details. Those can be found in the SAP BTP Cockpit: the organization, space and service instance name of the ABAP Environment system as well as a user with access to the space. The credentials for the user must be saved in the Jenkins Credentials store using an identifier – ‘cfUser’ in this example.

With this change, the entry barrier is lower than before. We hope you are encouraged to take your first steps in the CI/CD world, while we continue to work on extending the CI/CD possibilities.

Source: sap.com

No comments:

Post a Comment