---
schema_version: "1"
id: 0ecce54ca3b0c3ffcd09554524a09e6c564477eddaeafa4eb4c8f05c4faa6328
title: Assert Expression
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/munit/3.6/assertion-expression-processor.md
canonical_url: https://docs.mulesoft.com/munit/3.6/assertion-expression-processor
source_site: docs.mulesoft.com
content_type: documentation
content_hash: dacbee9fec3592876372e30d4f1340a8e7833aecba3518aef7c08034d8e0d460
description: MuleSoft Documentation Site
release: "3.6"
latest: false
---
---
product: MUnit
version: 3.6
---

# Assert Expression

> 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 Assert Expression processor allows you evaluate a Dataweave expression that asserts the state of
a Mule Event’s content. This processor can be used to validate the Mule Event after the production
code runs, using the [DataWeave Assertions Library](https://docs.mulesoft.com/munit/3.6/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 `java.lang.AssertionError`.

> [!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.
