Tutorial: Invoking test cases from Jenkins with JUnit result format

In this tutorial, you start a test case using injected variables from a Jenkins pipeline.

Before you begin

You must have the Automated API behavior testing application enabled and have created and published at least one test. You must have a Jenkins instance that you can create a new build in with the JUnit Plugin installed

About this task

This tutorial takes you through the following steps.
  1. Creating an API Hook
  2. Creating an API Key and Secret
  3. Creating a Jenkins build that invokes the API Hook
  4. Executing the build and reviewing the test results

Procedure

  1. To create an API Hook, see Creating an API Hook.
  2. To create an API key and secret, see Creating an API Key and Secret.
  3. To create a Jenkins project or navigate to an existing one, complete the following steps.
    1. Select Configure from the the options Configure Jenkins Project
    2. Under Build, click Add build step drop-down and select Execute Shell Jenkins execute shell
    3. Within the Execute shell block paste a curl command that will invoke the hook that was created in step 1.
      curl -XPOST
      -H 'x-api-key: <API-KEY>'
      -H 'x-api-secret: <API-SECRET>'
      -H "Content-type: application/json"
      -d '{ options: { JUnitFormat: true }}'
      '<API-HOOK-URL>/tests/run'
      >| testReports.xml
    4. Under Post-build Actions, click Add post-build action and in the drop-down select Publish JUnit test results report.
    5. For Test report XMLs provide the name of the report created from the curl, in this tutorial testReports.xml Jenkins Post build action
    6. Save the project.
  4. To execute the build and review the test results, complete the following steps.
    1. Click Build Now on the project:Jenkins Build Now
    2. Once the build has completed, you will now see a chart showing:Jenkins Project Page
    3. Click Latest Test results and review the Junit results:Jenkins individual build results

    For more information, see Using API Hooks

Results

In this tutorial you completed the following activities:
  • Created a API Hook
  • Created a Key and Secret used for authenticating with a hook
  • Invoked the API Hook using the Key and Secret to start a test and process the results