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.
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.
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.
Go to Help > Install New Software…
Set the following properties:
MUnit Update Site
Check Munit and Munit Tools for Mule, and click Next to complete the installation.
After installation, restart Anypoint Studio.
To generate a test suite:
Stop any Mule applications that are running from Studio.
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.
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:
GETrequest receives a
200status 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.