To Test an API

You can use Anypoint Studio to change and test an API. MUnit can create a unit testing suite for your application.

Using MUnit for Unit Testing

A unit test consists of verifying that a single unit of code works as expected. Use MUnit to ensure the core functions of your application behave as you intended. MUnit is the Mule application testing framework that allows you to build automated tests for your integrations and APIs. We recommend integrating MUnit into your continuous deployment environment.

In this particular example, you focus on verifying the status and payloads returned by your APIKit router configuration following your RAML specs.

Later on, you can choose to automate each test to run before you deploy the application to guarantee the app works according to your design.

After you install MUnit as indicated below, work with its integrated automatic test creator to build the necessary tests for a RAML-based application.

Install MUnit

MUnit comes bundled with Studio 5.4.0 and later. If you are running an older Studio version, you first need to install MUnit. Using MUnit you can design your tests the same way you design a Mule application in Studio. You to automatically generate a test suite based on the RAML definition used by your APIKit router. In this case, MUnit creates a test for every flow created in your Mule application with the purpose of verifying the expected http status code and response payload of every flow.

  1. Go to Help > Install New Software…​

  2. Click Add…​

  3. Set the following properties:

    • Name to MUnit Update Site

    • Location to

  4. Check Munit and Munit Tools for Mule, and click Next to complete the installation.

  5. After installation, restart Anypoint Studio.

Generate an MUnit Test Suite

To generate a test suite:

  1. Stop any Mule applications that are running from Studio.

  2. Right-click the APIKit Router >, MUnit > Create placeholder.xml Suite for RAML.

MUnit creates a test for each flow in your application and returns an MUnit test suite.

Perform a Test

It is important to define the purpose of your test. This automatic test validates the payloads and http response codes returned by your exposed APIKit endpoint. You test for the following things:

  • A GET request receives a 200 status code response.

  • The payload of this response is the one you are expecting.

To test this application, right click any blank space in your Test Suite workspace and select Run MUnit Suite.

The result of every test is shown in the MUnit View in Anypoint Studio.