Overview:
MUnit is a framework provided by MuleSoft to perform the unit testing and integration testing. It validates the flow in MuleESB and provides set of tools (connectors), such as a Message Processor mocking tests to make Automation easy. One of the benefits of MUnit is that it verifies whether an org is integrated properly or not. With the help of MUnit, we can achieve best Automation test coverage in MuleESB.
- Unit testing: Validation of smallest unit of code.
- Integration testing: Validation of collaboration of units.
Boundaries:
- Write short flows: Since the large flow has so many logic/rules, we need to split the flow into short flows.
- Modularize: Divide your application based on functional areas. Don’t write everything into single xml file but create different xml files and add your flows depending on the goal of the flow.
- Environmentalism: Always use placeholder in your code wherever you can, especially for outbound connecters like DB which are going to change based on environment.
- Readability and Maintainability: Always use proper names to understand easily
- Error Message: Always throw proper error messages.
Configuration Framework:
Step 1:
- Open ‘Anypoint Studio’
- Click on ‘HELP’ (In toolbar)
- A dropdown list is shown
- Click on ‘Install New Software’
- Search box- paste ‘MUnit Update Sit http://studio.mulesoft.org/r5/munit’
Step 2:
- Click the checkboxes shown in the following figure
- Click the Next button to install
- Click the Finish button to complete the MUnit configuration
Mule Studio
Fig 1.1: Client Org
Salesforce Configuration: Here I Query the records from an Inbound Salesforce endpoint.
Fig 1.2: Customer Org
Salesforce Configuration: Here I get input from an Inbound Salesforce endpoint as a payload and pass it to an Outbound Salesforce endpoint.
Fig 1.3: Studio Configuration Results
Postman: Need to pass the URL to kick start the integrated Flow.
Fig 1.4: Tracker message shown
Console: In this, we get the tracker message to show the status of the configuration.
Fig 1.5: MUnit Flow in Mule Studio
Mock: It is an inbound connector which mocks all Inbound endpoints in our flows while running MUnit test cases.
Flow Reference: Here it refers the Mule flow
Assert Equal: This will check whether the name of the record is equal or not
Fig 1.6: Run Munit suite
Fig 1.7: Results of MUnit test cases
Once it completes, if there are no errors in integration between the both Org, then it will show result as below.
Fig 1.8: Failed test cases
If there are any integration issues, then we get the results as below.