---
schema_version: "1"
id: 19e4a7d91626f9cbb4e9a6692b8002645deaa831b69c39a2740b97b4998a4bb5
title: Assert Expression
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/munit/2.3/assertion-expression-processor.md
canonical_url: https://docs.mulesoft.com/jp/munit/2.3/assertion-expression-processor
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 3eb4cc9bbe8816e88db19463e0302bb36bc66ba312fbdfec98b349825b36aca3
description: MuleSoft Documentation Site
release: "2.3"
latest: false
---
# Assert Expression

Assert Expression プロセッサーでは、Mule イベントのコンテンツの状態をアサートする Dataweave 式を評価できます。このプロセッサーは、​[DataWeave アサーションライブラリ](https://docs.mulesoft.com/jp/munit/2.3/dataweave-assertions-library)​を使用して、本番コードの実行後に Mule イベントを検証するために使用できます。

たとえば、ペイロードが特定の値と等しいことをアサートするため、equalTo() マッチャーを使用して Assert-Expression プロセッサーを設定できます。

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

## [](#複雑なアサーションの実行)複雑なアサーションの実行

DW アサーションライブラリを使用すると、Mule イベントのコンテンツの状態をより深くアサートできます。

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

## [](#独自のマッチャーの作成)独自のマッチャーの作成

独自のマッチャーを作成するには、​`src/test/resources`​ フォルダーに DW ファイルを追加します。たとえば、次のコンテンツを含む ​`MyMatcher.dwl`​ というファイルを追加します。

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

次に、Assert-Expression プロセッサー内でそれを使用します。

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

このアサーションが失敗すると、プロセッサーは ​`java.lang.AssertionError`​ をスローします。

<table>
<tbody><tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
<div class="paragraph">
<p><code>dw::test::Asserts</code>​ ライブラリのマッチャーは、​<code>MunitTools</code>​ マッチャーとは互換性がありません。Assert-That プロセッサーで ​<code>dw::test::Asserts</code>​ は使用できず、Assert-Expression プロセッサーで ​<code>MunitTools</code>​ マッチャーは使用できません。</p>
</div>
</td>
</tr>
</tbody></table>