Technical Articles
Testing ABAPUnit using POSTMAN
When you are executing gctsExecuteABAPUnitTests pipeline in Jenkins and getting errors like 405 etc.; you can test the ABAPUnit functionality by using POSTMAN to find the root cause of errors
- Firstly, get the X-CSRF-TOKEN using GET Request in POSTMAN.
In Postman, using GET Request where xxxxxxx is server name
http://xxxxxxx.com:50000/sap/opu/odata/SAP/adt_srv
In header tab, add the below syntax
This will return x-csrf-token
2. And afterward you can use the Request POST http://xxxxxxx..com:50000/sap/bc/adt/abapunit/testruns?sapclient=100
In Header, pass the CSRF Token obtained from step 1 and pass the key values for Accept and Content-Type as shown below
In the Body part; pass the below details – you need to pass the object name on which you plan to execute ABAPUnit
<?xml version=”1.0″ encoding=”UTF-8″?>
<aunit:runConfiguration xmlns:aunit=”http://www.sap.com/adt/aunit”>
<external>
<coverage active=”false”/>
</external>
<options>
<uriType value=”semantic”/>
<testDeterminationStrategy appendAssignedTestsPreview=”true” assignedTests=”false” sameProgram=”true”/>
<testRiskLevels critical=”true” dangerous=”true” harmless=”true”/>
<testDurations long=”true” medium=”true” short=”true”/>
<withNavigationUri enabled=”false”/>
</options>
<adtcore:objectSets xmlns:adtcore=”http://www.sap.com/adt/core”>
<objectSet kind=”inclusive”>
<adtcore:objectReferences>
<adtcore:objectReference adtcore:uri=”/sap/bc/adt/oo/classes/CLASS_NAME“/>
</adtcore:objectReferences>
</objectSet>
</adtcore:objectSets>
</aunit:runConfiguration>
Example in place of CLASS_NAME pass value of class ‘ZCL_ABAPUNIT_DEMO’ on which you plan to execute ABAP Unit. If everything is fine; it will return the status code as 200 and below response :
<?xml version=”1.0″ encoding=”utf-8″?>
<aunit:runResult xmlns:aunit=”http://www.sap.com/adt/aunit”>
<program adtcore:uri=”/sap/bc/adt/oo/classes/zcl_abapunit_demo” adtcore:type=”CLAS/OC” adtcore:name=”ZCL_ABAPUNIT_DEMO” uriType=”semantic” xmlns:adtcore=”http://www.sap.com/adt/core”>
<testClasses>
<testClass adtcore:uri=”/sap/bc/adt/oo/classes/zcl_abapunit_demo#testclass=LTCL_” adtcore:name=”LTCL_” uriType=”semantic” durationCategory=”short” riskLevel=”harmless”>
<testMethods>
<testMethod adtcore:uri=”/sap/bc/adt/oo/classes/zcl_abapunit_demo#testclass=LTCL_;testmethod=FIRST_TEST” adtcore:name=”FIRST_TEST” executionTime=”0″ uriType=”semantic” unit=”s”/>
</testMethods>
</testClass>
</testClasses>
</program>
</aunit:runResult>
In case of any errors, it will not return status code as 200 and you can validate the reason behind the errors as shown in response
Regards
Taranam
Interesting that we can run ABAPUnit from POSTMAN as well ;thanks for sharing