---
schema_version: "1"
id: 00a0f78b44a29548c293983265d833f5c0901ed6e6c7d952fa525598d15b7976
title: MUnit Assert Expression Processor
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/munit/latest/assertion-expression-processor.md
canonical_url: https://docs.mulesoft.com/munit/latest/assertion-expression-processor
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 6f130f7d77aa549734b604de7b783578306ccfd8cd274f01bf95b31de0910643
description: MuleSoft Documentation Site
release: "3.7"
latest: true
---
---
product: MUnit
version: 3.7
is-latest-version: true
---

# MUnit Assert Expression Processor

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

![logo acb active](/mulesoft/current/en-us/_/img/icons/anypoint-code-builder.svg "Anypoint Code Builder")Anypoint Code
Builder

![logo studio active](/mulesoft/current/en-us/_/img/icons/studio.svg "Anypoint Studio")Anypoint Studio

The MUnit Assert Expression processor evaluates DataWeave expressions to validate a Mule event’s
content during a MUnit test, using the DataWeave Assertions Library. Use it when you need
DataWeave-native assertions or want to create custom matchers with the DataWeave Assertions Library.

For example, to assert that a payload is equal to a certain value, you can configure the
Assert-Expression processor using the equalTo() matcher.

```xml
<munit-tools:assert>
    <munit-tools:that>#[ import * from dw::test::Asserts ---
        payload must equalTo('example') ]
    </munit-tools:that>
</munit-tools:assert>
```

## Perform Complex Assertions

The DW assertions library allows you to assert the state of the Mule Event’s content in a deeper
way.

```xml
<munit-tools:assert>
    <munit-tools:that>#[ import * from dw::test::Asserts ---
        vars.attributes must [beObject(), $.statusCode must equalTo(200), $.method must equalTo('GET')] ]
    </munit-tools:that>
</munit-tools:assert>
```

## Create Your Own Matcher

To create your own matcher, you can add DW files to your `src/test/resources` folder. For example, a
file called `MyMatcher.dwl` with the following content:

```dataweave
import * from dw::test::Asserts

fun beEven(): Matcher<Number> =
     (actual:Number) -> do {
         var matchesEven = (actual mod 2) == 0
         ---
         {
             matches: matchesEven,
             description: {expected: " to be an even number.", actual: write(actual) as String}
         }
     }
```

And then use it in your Assert-Expression processor:

```xml
<munit-tools:assert>
    <munit-tools:that>#[ import * from dw::test::Asserts ---
        payload must MyMatcher::beEven() ]
    </munit-tools:that>
</munit-tools:assert>
```

If this assertion fails, the processor throws a `MUNIT-TOOLS:ASSERTION_ERROR`.

> [!WARNING] Matchers from the `dw::test::Asserts` library are not compatible with the `MunitTools`
> matchers. You can’t use `dw::test::Asserts` with the Assert-That processor, and you can’t use
> `MunitTools` matchers with the Assert-Expression processor.
