Continuous Integration in ABAP

Continuously testing your ABAP codes with ADT APIs, Postman, and Jenkins

Image for post
Image for post

What is Continuous Integration (CI)?

Continuous Integration (CI) is a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early.

By integrating regularly, you can detect errors quickly, and locate them more easily.

ThoughWorks

What Does This Mean for ABAP?

Image for post
Image for post

Checking In ABAP Codes to Git

Image for post
Image for post

Exploring ADT APIs

Image for post
Image for post

ABAP Communication Log

Image for post
Image for post
ABAP Communication Log of an ABAP Unit request
Image for post
Image for post
A HTTP Message detail of ABAP Unit API

API Automation with Postman

Image for post
Image for post

Writing Test Script

Image for post
Image for post
A Sample Postman Test Script

Design Your CI Pipeline

Image for post
Image for post
Continuous Integration Pipeline for ABAP

Implementing Your Scripts

Testing Your Script

Image for post
Image for post
A Postman Test Result of ABAP Unit and Code Coverage Collection
Image for post
Image for post
A Postman Collection Test Result of SCI Collection

Exporting Your Script

Integrating Postman Scripts into Jenkins

Image for post
Image for post

Pull code from Git

Image for post
Image for post
A Jenkins Job to Pull Codes From GitHub
Image for post
Image for post
Job Schedule in Jenkins — Polling SCM Every Minutes

Run ABAP Unit and Code Coverage

Image for post
Image for post
A Jenkins Job to Run Postman Script to Run ABAP Unit and Code Coverage
C:\Program Files (x86)\Jenkins\workspace\ABAP Unit Coverage>cd C:\Users\administrator\Documents\Git\abap-ci-postmanC:\Users\administrator\Documents\Git\abap-ci-postman>call newman run abap_unit_coverage.postman_collection.json --environment NPL.postman_environment.json 
newman
abap_unit_coverage→ GetToken

│ '==========Environment Variables=========='
│ 'protocol=http'
│ 'host=vhcalnplci.dummy.nodomain'
│ 'port=8000'
│ 'authorization=Basic xxx'
│ 'package=$REST'
│ 'coverage_type=statement'
│ 'coverage_min=80'
│ 'coverage_maxlevel=2'
│ 'coverage_chklevel=0'
│ 'exclusion=[{"name":"ZCL_COMPLEX_RESPONSE==========CP","type":"CLAS/O
│ CI","reason":"Data model class"}]'
│ 'atc_variant=DEFAULT'
│ 'x-csrf-token=YE9m7YEdPAEI7Zcj2KPn8Q=='

GET http://vhcalnplci.dummy.nodomain:8000/sap/bc/adt/abapunit [404 Not Found,843B, 106ms]
√ X-CSRF-Token is present
→ RunABAPUnit
POST http://vhcalnplci.dummy.nodomain:8000/sap/bc/adt/abapunit/testruns [200 OK, 2.71KB, 2.4s]
√ Status code is 200
√ Job finished successfully
√ No critical alert for $REST/CLAS/OC/ZCL_REST_HANDLER [Actual=0]
√ No critical alert for $REST/CLAS/OC/ZCL_REST_RESOURCE [Actual=0]
√ Coverage ID 000D3AA2B4DA1EE7A5C18580FC24BF6F
→ CheckCodeCoverage
POST http://vhcalnplci.dummy.nodomain:8000/sap/bc/adt/runtime/traces/coverage/
measurements/000D3AA2B4DA1EE7A5C18580FC24BF6F [200 OK, 5.57KB, 116ms]
√ Status code is 200
√ >>CLAS/OCI/ZCL_COMPLEX_RESPONSE==========CP statement coverage = NA% [Exclu
ded: Data model class]
√ >>>>CLAS/OCI/ZCL_REST_HANDLER statement coverage = 100.00%
√ >>CLAS/OCI/ZCL_REST_HANDLER==============CP statement coverage = 100.00%
√ >>>>CLAS/OCI/ZCL_REST_RESOURCE statement coverage = 100.00%
√ >>CLAS/OCI/ZCL_REST_RESOURCE=============CP statement coverage = 100.00%
√ DEVC/K/$REST statement coverage >= 80% [Actual=100.00%]
┌─────────────────────────┬──────────┬──────────┐
│ │ executed │ failed │
├─────────────────────────┼──────────┼──────────┤
│ iterations │ 1 │ 0 │
├─────────────────────────┼──────────┼──────────┤
│ requests │ 3 │ 0 │
├─────────────────────────┼──────────┼──────────┤
│ test-scripts │ 3 │ 0 │
├─────────────────────────┼──────────┼──────────┤
│ prerequest-scripts │ 1 │ 0 │
├─────────────────────────┼──────────┼──────────┤
│ assertions │ 13 │ 0 │
├─────────────────────────┴──────────┴──────────┤
│ total run duration: 3.1s │
├───────────────────────────────────────────────┤
│ total data received: 8.14KB (approx) │
├───────────────────────────────────────────────┤
│ average response time: 869ms │
└───────────────────────────────────────────────┘
C:\Users\administrator\Documents\Git\abap-ci-postman>exit 0
Finished: SUCCESS

Run Code Inspector (SCI)

Image for post
Image for post
A Jenkins Job to Run Postman Script to Run SCI (via ATC)
C:\Program Files (x86)\Jenkins\workspace\ABAP Code Inspector>cd C:\Users\administrator\Documents\Git\abap-ci-postmanC:\Users\administrator\Documents\Git\abap-ci-postman>call newman run abap_sci.postman_collection.json --environment NPL.postman_environment.json 
newman
abap_sci→ GetToken

│ '==========Environment Variables=========='
│ 'protocol=http'
│ 'host=vhcalnplci.dummy.nodomain'
│ 'port=8000'
│ 'authorization=Basic xxx'
│ 'package=$REST'
│ 'coverage_type=statement'
│ 'coverage_min=80'
│ 'coverage_maxlevel=2'
│ 'coverage_chklevel=0'
│ 'exclusion=[{"name":"ZCL_COMPLEX_RESPONSE==========CP","type":"CLAS/O
│ CI","reason":"Data model class"}]'
│ 'atc_variant=DEFAULT'
│ 'x-csrf-token=YE9m7YEdPAEI7Zcj2KPn8Q=='

GET http://vhcalnplci.dummy.nodomain:8000/sap/bc/adt/abapunit [404 Not Found,835B, 125ms]
√ X-CSRF-Token is present
→ CreateWorklist
POST http://vhcalnplci.dummy.nodomain:8000/sap/bc/adt/atc/worklists?checkVariant=DEFAULT [200 OK, 182B, 47ms]
√ Status code is 200
√ Worklist ID 000D3AA2B4DA1EE7A5C19C55F9953F86
→ RunATC
POST http://vhcalnplci.dummy.nodomain:8000/sap/bc/adt/atc/runs?worklistId=000D3AA2B4DA1EE7A5C19C55F9953F86 [200 OK, 601B, 2.6s]
√ Status code is 200
√ No error found [Actual=0,0,7]
┌─────────────────────────┬──────────┬──────────┐
│ │ executed │ failed │
├─────────────────────────┼──────────┼──────────┤
│ iterations │ 1 │ 0 │
├─────────────────────────┼──────────┼──────────┤
│ requests │ 3 │ 0 │
├─────────────────────────┼──────────┼──────────┤
│ test-scripts │ 3 │ 0 │
├─────────────────────────┼──────────┼──────────┤
│ prerequest-scripts │ 1 │ 0 │
├─────────────────────────┼──────────┼──────────┤
│ assertions │ 5 │ 0 │
├─────────────────────────┴──────────┴──────────┤
│ total run duration: 3.4s │
├───────────────────────────────────────────────┤
│ total data received: 573B (approx) │
├───────────────────────────────────────────────┤
│ average response time: 936ms │
└───────────────────────────────────────────────┘
C:\Users\administrator\Documents\Git\abap-ci-postman>exit 0
Finished: SUCCESS

Create the Pipeline

Image for post
Image for post
A Jenkins Build Pipeline
Image for post
Image for post
A Jenkins Build Monitor View

Continuous Integration doesn’t get rid of bugs, but it does make them dramatically easier to find and remove.

— Martin Fowler

Image for post
Image for post

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store