Learn more about MUnit and learn more about how to test Mule.
MUnit is a Mule application testing framework which allows you to build automated tests for your Mule integrations and API’s. MUnit is very well integrated with Anypoint Studio.
Various features available with Mule MUnit:
- Create and build Mule tests by writing Mule code.
- Create and build Mule tests by writing Java code.
- Verify Message Processor calls.
- Mock Message Processor.
- Mock outbound endpoints.
- Disable outbound endpoints.
- Disable flow inbound connectors.
- Disable inbound endpoints.
- Debug the tests.
- View coverage reports.
- Various asserts available like Assert Equals, Assert Not Equals, Assert Payload, Assert False, Assert True, Assert Null Payload, Assert Not Null Payload.
- Spy Message Processor.
In this article, we will see how to create and run the MUnit tests.
Install MUnit
First, you want to make sure MUnit is installed in your Anypoint Studio. In case it is not installed, follow below steps.
Go to Help > Install New Software…
Now, it will open new pop-up windows. Select MUnit Update Site from drop down list. Check MUnit and MUnit Tools for Mule.
Finally, just click Next and accept the license terms and conditions. Click Finish and it will install MUnit tools in your Anypoint Studio.
Create MUnit Tests for Mule Flow
For creating MUnit tests for your application, right click on the flow select MUnit > Create New MUnit.
It will create MUnit tests for the flow and it will be available in folder src/test/unit.
In Assert Payload, you need to define Expected Value and in this case, it will be payload. Also, provide Test Failure Message, in case the value doesn’t message the expected value then it will provide the failure message you have defined.
Run MUnit Tests
For running MUnit tests, right click the canvas region of the MUnit test flow and select Run MUnit suite.
After running the MUnit suite, it will provide details like errors, failures (if any), coverage report, and test status.
In above image, the green color means that your test case has been successfully executed and passed.
Now you know how to create MUnit tests for your flow!
For a video walkthrough, please refer to the tutorial below:
This blog post is from a MuleSoft Champion and first appeared on Dzone