---
schema_version: "1"
id: 3b981864cdb5466c91a683a3d1a5fb1042b8ba3a50a257b4a094ef5bd081831d
title: Migrating Test Structure (MUnit)
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/mule-runtime/4.4/migration-munit-test-structure.md
canonical_url: https://docs.mulesoft.com/mule-runtime/4.4/migration-munit-test-structure
source_site: docs.mulesoft.com
content_type: documentation
content_hash: f359923563d583be9409b8238d37e5622c5d3d1b616ced1906bcfda924464973
description: MuleSoft Documentation Site
release: "4.4"
latest: false
---
---
product: Mule Runtime
version: 4.4
---

# Migrating Test Structure (MUnit)

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

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

<table><colgroup><col> <col></colgroup><thead><tr><th>Scope</th><th>Description</th></tr></thead><tbody><tr><td><p>Behavior</p></td><td><p>The behavior scope (<code>&lt;munit:behavior/&gt;</code>) is intended for setting the preconditions before executing the test logic.<br>Mocks and Spies go in this section.</p></td></tr><tr><td><p>Execution</p></td><td><p>The execution scope (<code>&lt;munit:execution/&gt;</code>) is meant to have the testing logic which will wait for all processes to finish before executing the next scope.</p></td></tr><tr><td><p>Validation</p></td><td><p>The validation scope (<code>&lt;munit:validation/&gt;</code>) is meant to have all the validations regarding the result of the execution scope.<br>Assertions and Verifications go in the validation scope.</p></td></tr></tbody></table>

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

Test in MUnit 1.x

```xml
<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

```xml
<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>
```

## See Also

- [MUnit 2 Test structure](https://docs.mulesoft.com/munit/latest/munit-test-concept)
