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

# Assert Expression

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

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/2.3/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.
