---
schema_version: "1"
id: 873fe6964ba988d0b949cc7d52790a6b472c76043cc549ad3d5fbd3c1bc4ec9c
title: パラメーター化
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/munit/2.3/parameterized.md
canonical_url: https://docs.mulesoft.com/jp/munit/2.3/parameterized
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 4684092928e4879977aeb4a8e990052b07055f702616b6aab46f87480b34db84
description: MuleSoft Documentation Site
release: "2.3"
latest: false
---
# パラメーター化

パラメーター化されたテストスイートでは、異なる入力で同じテストが実行されます。

テストスイートのパラメーター化は、次のように設定レベルで定義されます。

```xml
<munit:config>
    <munit:parameterizations>
        <munit:parameterization name="firstParameterization">
            <munit:parameters>
                <munit:parameter propertyName="name" value="Robert"/>
                <munit:parameter propertyName="lastname" value="Plant"/>
            </munit:parameters>
        </munit:parameterization>
        <munit:parameterization name="secondParameterization">
            <munit:parameters>
                <munit:parameter propertyName="name" value="Jimmy"/>
                <munit:parameter propertyName="lastname" value="Page"/>
            </munit:parameters>
        </munit:parameterization>
    </munit:parameterizations>
</munit:config>
```

テストスイートは 2 回実行されます。最初は ​`firstParameterization`​ パラメーターで実行されます。2 回目は ​`secondParameterization`​ パラメーターで実行されます。

たとえば、フローのペイロードを設定するテストがある場合、次のような結果が想定されます。

パラメーター化の例

```xml
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:munit="http://www.mulesoft.org/schema/mule/munit"
      xmlns:munit-tools="http://www.mulesoft.org/schema/mule/munit-tools"
      xsi:schemaLocation="
        http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
        http://www.mulesoft.org/schema/mule/munit http://www.mulesoft.org/schema/mule/munit/current/mule-munit.xsd
        http://www.mulesoft.org/schema/mule/munit-tools http://www.mulesoft.org/schema/mule/munit-tools/current/mule-munit-tools.xsd">

    <munit:config name="parameterized-test.xml">
        <munit:parameterizations>
            <munit:parameterization name="sumThree">
                <munit:parameters>
                    <munit:parameter propertyName="input" value="#[1]"/>
                    <munit:parameter propertyName="output" value="#[2]"/>
                </munit:parameters>
            </munit:parameterization>
            <munit:parameterization name="sumFive">
                <munit:parameters>
                    <munit:parameter propertyName="input" value="#[2]"/>
                    <munit:parameter propertyName="output" value="#[4]"/>
                </munit:parameters>
            </munit:parameterization>
        </munit:parameterizations>
    </munit:config>

    <munit:test name="expectFlowResult">
        <munit:behavior>
            <set-payload value="${input}"/>
        </munit:behavior>
        <munit:execution >
            <flow-ref name="myFlow"/>
        </munit:execution>
        <munit:validation>
            <munit-tools:assert-equals actual="#[payload]" expected="${output}" />
        </munit:validation>
    </munit:test>

</mule>
```

## [](#ファイルからのパラメーター化)ファイルからのパラメーター化

異なるテストスイートで同じパラメーター化された値を使用するには、パラメーター化の値を Mule アプリケーションプロジェクトの ​`/test/resources`​ ディレクトリの YAML ファイルに保存する必要があります。

parameterizations.yaml の例

```yaml
firstParameterization:
    name: "Robert"
    lastname: "Plant"

secondParameterization:
    name: "Jimmy"
    lastname: "Page"
```

次に、それをテストスイート設定から参照します。

ファイルからのパラメーター化の例

```xml
<munit:config>
    <munit:parameterizations file="parameterizations.yaml" />
</munit:config>
```

両方の方法を組み合わせて、パラメーター化された値をテストスイートに追加できます。

ファイルおよびテストスイート設定からのパラメーター化の例

```xml
<munit:config name="parameterization-from-file-test.xml">
    <munit:parameterizations file="parameterizations.yaml" >
        <munit:parameterization name="thirdParameterization">
            <munit:parameters>
                <munit:parameter propertyName="name" value="John"/>
                <munit:parameter propertyName="lastname" value="Bonham"/>
            </munit:parameters>
        </munit:parameterization>
    </munit:parameterizations>
</munit:config>
```

YAML ファイルとテストスイート設定で同じパラメーター化キーを定義した場合、テストスイートのパラメーター化が YAML のパラメーター化よりも優先されます。