Tutorial: Invoking test cases from Jenkins with JUnit result format

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 tutorial

In this tutorial, you invoke a test case using injected variables from a jenkins pipeline

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

Creating an API Hook

See Creating an API Hook

Creating an API Key and Secret

See Creating an API Key and Secret

Creating a Jenkins build that invokes the API Hook

  1. Create a Jenkins Project or navigate to an existing one

  2. Select Configure from the the options
    Configure Jenkins Project

  3. Under Build, click Add build step dropdown and select Execute Shell
    Jenkins execute shell

  4. 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
    
  5. Under Post-build Actions, click Add post-build action and in the dropdown select Publish JUnit test results report.

    1. 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

Executing the build and reviewing the test results

  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

To expand upon this tutorial additional options and steps can be found under Using API Hooks

What you did in this tutorial

In this tutorial you completed the following activities:

  • Created a API Hook
  • Created a Key and Secret used for authenicating with a hook
  • Invoked the API Hook using the Key and Secret to start a test and process the results