Skip to content

Latest commit

 

History

History
356 lines (228 loc) · 8.78 KB

running-abap-unit-test-runs-cdd19e3.md

File metadata and controls

356 lines (228 loc) · 8.78 KB

Running ABAP Unit Test Runs

ABAP Unit is the standard tool for running unit tests. In this help topic, you'll learn how to start an ABAP Unit Test Run via REST Service.

For more information about ABAP Unit, see Ensuring Quality of ABAP Code.

  1. Get CSRF token: The first step serves for the authentication on the server. The response header contains a CSRF token, which is used as authentication for the POST request following in step 2.

    Request

    Authentication Type: Basic Authentication

    GET https://<host.com>:<port>/sap/bc/adt/api/abapunit/runs/00000000000000000000000000000000

    Headers

    KEY

    VALUE

    accept

    application/vnd.sap.adt.api.abapunit.run-status.v1+xml

    x-csrf-token

    fetch

    Response

    Headers

    KEY

    VALUE

    x-csrf-token

    <token>

    location

    /sap/bc/adt/api/abapunit/runs/00000000000000000000000000000000

  2. Start an ABAP Unit Run: To start an ABAP Unit run, insert theCSRF token that was retrieved in the first request in the header parameters.

    Request

    POST https://<host.com>:<port>/sap/bc/adt/api/abapunit/runs

    Headers

    KEY

    VALUE

    x-csrf-token

    <token>

    content type

    application/vnd.sap.adt.api.abapunit.run.v1+xml

    Body

    You can specify arbitrary object sets. See also Object Sets and XML Representations of Object Sets for more details.

    You can provide additional parameters to control the selection of tests. You can restrict the amount of tests to certain risk level and durations. Furthermore, you can decide to run foreign tests, which are connected via test relations.

    <?xml version="1.0" encoding="UTF-8"?>
    <aunit:run title="My Run" context="AIE Integration Test" xmlns:aunit="http://www.sap.com/adt/api/aunit">
      <aunit:options>
        <aunit:measurements type="none"/>
        <aunit:scope ownTests="true" foreignTests="true"/>
        <aunit:riskLevel harmless="true" dangerous="true" critical="true"/>
        <aunit:duration short="true" medium="true" long="true"/>
      </aunit:options>
      <osl:objectSet xsi:type="unionSet" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:osl="http://www.sap.com/api/osl">
       <osl:set xsi:type="osl:packageSet">
         <osl:package includeSubpackages="true" name="PACKAGE_ONE"/>
       </osl:set>
       <osl:set xsi:type="osl:flatObjectSet">
         <osl:object name="ZCL_TEST_ONE" type="CLAS"/>
         <osl:object name="ZIF_TEST_TWO" type="INTF"/>
       </osl:set>
      </osl:objectSet>
    </aunit:run>
    

    Response

    Headers

    KEY

    VALUE

    location

    /sap/bc/adt/api/abapunit/runs/{runId}

  3. **Tracking the Status of the Test Run:**To track the status of the test run, you can make a GET request using the URI contained in the location header.

    Request

    GET https://<host.com>:<port>/sap/bc/adt/api/abapunit/runs/{runId}

    Headers

    KEY

    VALUE

    accept

    application/vnd.sap.adt.api.abapunit.run-status.v1+xml

    Response

    While the tests are still running, the returned status will be ”In Process”.

    If all tests have been run, the status “Completed” is returned. You'll find the link /sap/bc/adt/api/atc/results/<UUID> at the bottom of the body. Use this link to retrieve the ABAP Unit test results in the next step.

    Body

    <?xml version="1.0" encoding="UTF-8"?>
    <aunit:run xmlns:aunit="http://www.sap.com/adt/api/aunit" title="MyTitle" context="MyContext">
      <aunit:progress status="FINISHED" percentage="100" />
      <aunit:executedBy user="JOHNDOE" />
      <aunit:time started="2021-02-12T17:09:19Z" ended="2021-02-12T17:09:22Z" />
      <atom:link xmlns:atom="http://www.w3.org/2005/Atom" href="/sap/bc/adt/api/abapunit/results/0123821392189313" rel="http://www.sap.com/adt/relations/api/abapunit/run-result" type="application/vnd.sap.adt.api.junit.run-result.v1+xml"/>
    </aunit:run>
    
  4. Retrieve Results: To get the ABAP Unit results, use the following request.

    Request

    GEThttps://<host.com>:<port>/sap/bc/adt/api/abapunit/results/{resultId}

    Headers

    KEY

    VALUE

    Accept

    application/vnd.sap.adt.api.junit.run-result.v1+xml

    Response

    The results are submitted in the JUnit format.

    Body

    As an example, the result may look like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <testsuites tests="3" asserts="2" skipped="1" errors="0" failures="1" timestamp="2021-01-22T19:17:30Z" time="0.36" executedBy="JOHNDOE" client="000" system="UIA">
        <testsuite tests="2" asserts="2" skipped="1" errors="0" failures="1" timestamp="2021-01-22T19:17:30Z" time="0.28 " hostname="ldai3uia" package="test_cars" name="">
            <testcase asserts="1" time="0.01 " name="order" classname="fugr:zmg_cars.ltc_finder">
                <failure type="Assert Failure" message="Critical Assertion Error: 'Cds_View: ASSERT_EQUALS'">
                Character string different as of position 4Expected [CL_AUNIT_TESTABLE_OBJECT======CP]Actual [CL_CAR========================CP] Test 'LTC_FINDER->ORDER' in Main Program 'SAPLZMG_CARS'
                Stack: Include: <LZMG_CARST99> Line: <38> (ORDER)
                </failure>
            </testcase>
            <testcase asserts="1" time="0.01 " name="preview" classname="fugr:zmg_cars.ltc_finder">
                <skipped message="Missing Prerequisites - Dummy: ABORT">
                Test execution skipped due to missing prerequisites Test 'LTC_FINDER->PREVIEW' in Main Program 'SAPLZMG_CARS'
                Stack: Include: <LZMG_CARST99> Line: <44> (PREVIEW)
                </skipped>
            </testcase>
            <testcase asserts="0" time="0.01 " name="drive" classname="fugr:zmg_cars.ltc_finder"/>
        </testsuite>
    </testsuites>