From the technical center of excellence of Massil Technologies, our technology leaders make it easy to understand the complex situations you come across in Mule ESB from the experience of Massil Technologies to have countered them in their experience of working on client projects in real time. This blog talks about how to check whether a string contains a substring in Mule ESB. This blog is a part of series of blogs being authored and published by Massil Technologies for the benefit of the IT community globally.
To check whether a string contains a substring, we will need to install Mule ESB testing framework called Munit. MUnit is a Mule testing framework that lets you easily automate testing Mule applications, using both unit and integration tests. MUnit also provides a set of tools, such as a message processor mocking framework that lets you test units of code in actual isolation.
To use MUnit in Studio, you have to install it from the website. To install MUnit, follow these steps:
MUnit Studio integration is mainly built around XML-based tests. Most of the MUnit-Studio integration tools guide you in the creation of these tests.
There are two basic ways to create a new MUnit test in Studio:
To create a test for a specific flow, right-click the flow, then select MUnit > Create a new <flow_name> suite.
To add an MUnit message processor to the test shown above, drag it from the Palette to the Testarea before and after the flow-ref.set message and assert true
in assert true
To run a test suite, right-click the empty canvas where the suite resides, then select Run MUnit suite.
Studio displays the output from the running suite in the console.
Running a Test
To run a test, right-click the name of the test, then select Run MUnit Test.
To check that the test is actually running, view the output in the console. In order not to overwhelm the user, the default output provides little information, but enough to verify that the test has run.
An alternative way to run a test is to use the MUnit tab (see below).
The MUnit tab displays successful tests in green, failed tests in red.
The Coverage button in the image above allows you to see what flow the test covered, and the percentage of message processors in the flow that was covered by the test:
If you run more than one test, the MUnit tab displays a history of run tests. For failed tests, the Errorsbutton displays the stack trace, which you can copy to your clipboard. To copy the stack trace, right-click the name of the failed test, then select Copy Stack Trace.
As you can see in the image above, you can also use the MUnit tab to Running Your Test or debug your test, by selecting the appropriate menu option.
Clicking the debug button or the play button on the top right causes the last run or debug to be rerun. This rerun includes all tests that were run on the previous one. You can also select a single test from the previous run to rerun on its own.
Hence, we have gone through the step by step process to depict the way Massil Technologies team has addressed. Hope this article from Massil Technologies was useful for you. If you have any further queries on this topic, please reach out to firstname.lastname@example.org.