Contact Free trial Login

Migrating Test Structure (MUnit)

The MUnit test is divided into three scopes. All of them are optional:

Scope Description


The behavior scope (<munit:behavior/>) is intended for setting the preconditions before executing the test logic.
Mocks and Spies go in this section.


The execution scope (<munit:execution/>) is meant to have the testing logic which will wait for all processes to finish before executing the next scope.


The validation scope (<munit:validation/>) is meant to have all the validations regarding the result of the execution scope.
Assertions and Verifications go in the validation scope.

The following examples compare MUnit tests in 1.x to 2.x.

Test in MUnit 1.x
<munit:test name="sampleTest" description="Test">
    <mock:when messageProcessor="mule:set-payload">
        <mock:then-return payload="#['Sample']"/>
    <flow-ref name="sampleFlow"/>
    <munit:assert-payload-equals expectedValue="#['SampleString']"/>
Test in MUnit 2.x
<munit:test name="sampleTest" description="Test">
        <munit-tools:mock-when processor="mule:set-payload">
                <munit-tools:payload value="#['Sample']" />
        <flow-ref name="sampleFlow"/>
        <munit-tools:assert-that expression="#[payload]" is="#[MunitTools::equalTo('SampleString')]"/>

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub