Contact Free trial Login

Migrating Test Structure (MUnit)

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

Scope Description

Behavior

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

Execution

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.

Validation

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

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub