---
schema_version: "1"
id: 5eb67aecace1907311a41c1cbbd4bbde4069657f452b66022bff8b203a899b45
title: DataWeave アサーションライブラリ
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/munit/3.0/dataweave-assertions-library.md
canonical_url: https://docs.mulesoft.com/jp/munit/3.0/dataweave-assertions-library
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 171598d2b96e6bb14fb86dd25dff5d926f029483e16f89ad5e3246a6904b467e
description: MuleSoft Documentation Site
release: "3.0"
latest: false
---
# DataWeave アサーションライブラリ

## [](#dwtestasserts)dw::test::Asserts

このモジュールには、テストで使用するコアマッチャーのセットが含まれます。

例

```dataweave
%dw 2.0
import dw::tests::Asserts
---
payload must beObject()
```

ペイロードが Object (オブジェクト) 型かどうかを検証します。

## [](#関数)関数

### [](#anyof)anyOf

#### [](#anyofarraymatcherany-matcherany)anyOf(Array<Matcher<Any>>): Matcher<Any>

値が少なくとも 1 つの指定されたマッチャーを満たすことを検証します。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
"A Text" must anyOf([beObject(), beString()])
```

### [](#bearray)beArray

#### [](#bearray-matcher)beArray(): Matcher

指定された値が Array (配列) 型であることを検証します。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
[1, 4, 7] must beArray()
```

### [](#beblank)beBlank

#### [](#beblank-matcherstring-null)beBlank(): Matcher<String | Null>

文字列値が空白であることを検証します。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
"  " must beBlank()
```

### [](#beboolean)beBoolean

#### [](#beboolean-matcher)beBoolean(): Matcher

指定された値が Boolean (ブール) 型であることを検証します。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
true must beBoolean()
```

### [](#beempty)beEmpty

#### [](#beempty-matcherstring-object-array-null)beEmpty(): Matcher<String | Object | Array | Null>

値 (String (文字列)、Object (オブジェクト)、または Array (配列)) が空であることを検証します。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
[] must beEmpty()
```

### [](#begreaterthan)beGreaterThan

#### [](#begreaterthancomparable-boolean-matchercomparable)beGreaterThan(Comparable, Boolean): Matcher<Comparable>

アサートされた Comparable (比較可能) 値が少なくとも 1 つの指定された値より大きいことを検証します。

_inclusive_​ 引数を使用する場合と同様に使用できます。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
3 must beGreaterThan(2)
```

### [](#belowerthan)beLowerThan

#### [](#belowerthancomparable-boolean-matchercomparable)beLowerThan(Comparable, Boolean): Matcher<Comparable>

アサートされた Comparable (比較可能) 値が指定された値より低いことを検証します。

_inclusive_​ 引数を使用する場合と同様に使用できます。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
1 must beLowerThan(2)
```

### [](#benull)beNull

#### [](#benull-matcher)beNull(): Matcher

指定された値が Null 型であることを検証します。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
null must beNull()
```

### [](#benumber)beNumber

#### [](#benumber-matcher)beNumber(): Matcher

指定された値が Number (数値) 型であることを検証します。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
123 must beNumber()
```

### [](#beobject)beObject

#### [](#beobject-matcher)beObject(): Matcher

指定された値が Object (オブジェクト) 型であることを検証します。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
{ name : "Lionel", lastName: "Messi"} must beObject()
```

### [](#beoneof)beOneOf

#### [](#beoneofarrayany-matcher)beOneOf(Array<Any>): Matcher

値が指定された Array (配列) に含まれることを検証します。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
1 must beOneOf([1, "A Text", true])
```

### [](#bestring)beString

#### [](#bestring-matcher)beString(): Matcher

指定された値が String (文字列) 型であることを検証します。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
"A Text" must beString()
```

### [](#contain)contain

#### [](#containstring-matcherstring)contain(String): Matcher<String>

アサートされた String (文字列) に指定された String (文字列) が含まれることを検証します。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
"A Text" must contain("ex")
```

#### [](#containany-matcherarrayany)contain(Any): Matcher<Array<Any>>

アサートされた Array (配列) に指定された値が含まれることを検証します。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
[1, "A Text", true] must contain(1)
```

### [](#eachitem)eachItem

#### [](#eachitemmatcherany-matcherarrayany)eachItem(Matcher<Any>): Matcher<Array<Any>>

配列内の各項目が指定されたマッチャーを満たすことを検証します。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
[1,2,3] must eachItem(beNumber())
```

### [](#endwith)endWith

#### [](#endwithstring-matcherstring)endWith(String): Matcher<String>

アサートされた String (文字列) が指定された String (文字列) で終了することを検証します。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
"A Text" must endWith("xt")
```

### [](#equalto)equalTo

#### [](#equaltoany-unordered-boolean-matcherany)equalTo(Any, { unordered?: Boolean }): Matcher<Any>

値が別の値と等しいことを検証します。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
(1 + 2) must equalTo(3)
```

### [](#equaltoresource)equalToResource

#### [](#equaltoresourcestring-string-object-matcherany)equalToResource(String, String, Object): Matcher<Any>

指定された値がリソースファイルの内容と等しいことを検証します。

リソースファイルはクラスパスに属している必要があります。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
{ name: "Lionel", lastName: "Messi" } must equalToResource("user.json", "application/json")
```

### [](#haveitem)haveItem

#### [](#haveitemmatcherany-matcherarrayany)haveItem(Matcher<Any>): Matcher<Array<Any>>

配列の少なくとも 1 つの項目が指定されたマッチャーを満たすことを検証します。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
[1, true, "a text"] must haveItem(beNumber())
```

### [](#havekey)haveKey

#### [](#havekeystring-matcherobject)haveKey(String): Matcher<Object>

Object (オブジェクト) に指定されたキーが含まれることを検証します。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
{ name: "Lionel", lastName: "Messi" } must haveKey("name")
```

### [](#havesize)haveSize

#### [](#havesizenumber-matcherarray-string-object)haveSize(Number): Matcher<Array | String | Object>

配列に指定されたサイズが含まれることを検証します。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
[1, 4, 7] must haveSize(3)
```

### [](#havevalue)haveValue

#### [](#havevalueany-matcherobject)haveValue(Any): Matcher<Object>

Object (オブジェクト) に指定された値が含まれることを検証します。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
{ name: "Lionel", lastName: "Messi" } must haveValue("Messi")
```

### [](#must)must

#### [](#mustt-arrayvalue-t-matchert-matcherresult-boolean-matcherresult)must(T, Array<(value: T) → Matcher<T> | MatcherResult | Boolean>): MatcherResult

この関数では、式のマッチャーのリストを使用して値をアサートできます。

例

```dataweave
%dw 2.0
import dw::tests::Asserts
---
payload must [
    beObject(),
    $.foo is Null
]
```

#### [](#mustt-value-t-matchert-boolean-matcherresult)must(T, (value: T) → Matcher<T> | Boolean): MatcherResult

この関数では、式のマッチャーを使用して値をアサートできます。

例

```dataweave
%dw 2.0
import dw::tests::Asserts
---
payload must beObject()
```

### [](#notbe)notBe

#### [](#notbematchert-matchert)notBe(Matcher<T>): Matcher<T>

値が指定されたマッチャーを満たさないことを検証します。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
1 must notBe(equalTo(2))
```

### [](#notbenull)notBeNull

#### [](#notbenull-matcher)notBeNull(): Matcher

指定された値が Null 型ではないことを検証します。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
"A Text" must notBeNull()
```

### [](#startwith)startWith

#### [](#startwithstring-matcherstring)startWith(String): Matcher<String>

アサートされた String (文字列) が指定された String (文字列) で開始することを検証します。

```dataweave
%dw 2.0
import dw::tests::Asserts
---
"A Text" must startWith("A")
```

## [](#変数)変数

### [](#matched)MATCHED

成功した一致を表す定数。

## [](#型)型

### [](#matcher)Matcher

アサーションを実行するマッチャーを表すデータ型。

例

```dataweave
%dw 2.0
import dw::tests::Asserts

fun beEqualToOne(): Matcher<Any> =
    (actual) -> do {
        {
            matches: actual == 1,
            description: { expected: "To be 1", actual: write(actual) as String }
        }
    }
```

定義

```dataweave
(value: T) -> MatcherResult
```

### [](#matcherresult)MatcherResult

アサーションの結果を表すデータ型。

例

```dataweave
{
  "matches": false,
  description : { expected : "Number type", actual: "A Text" }
}
```

定義

```dataweave
{ matches: Boolean, description: { expected: String, actual: String }, reasons?: Array<String> }
```