---
schema_version: "1"
id: 0f00a3ac42cbd8d4b63eee484ac25a4d9f3ef9795d490a54da7132cd2a38a3c8
title: 環境プロパティを使用したテスト
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/munit/2.3/use-environment-properties-on-tests-cookbook.md
canonical_url: https://docs.mulesoft.com/jp/munit/2.3/use-environment-properties-on-tests-cookbook
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 6398b6f27eca2425ac0ad3a1d0b38757502c3c3181393c242feb9eba775c8b44
description: MuleSoft Documentation Site
release: "2.3"
latest: false
---
# 環境プロパティを使用したテスト

外部 API からデータを取得する次のフローがあり、MUnit テストの実行時にテスト環境からこのデータをコンシュームする必要があるとします。

```xml
<http:request-config name="HTTP_Request_configuration">
	<http:request-connection host="sampleapi.com/api/v1/" port="80"/>
</http:request-config>
<flow name="requestApiFlow">
	<http:request method="GET" config-ref="HTTP_Request_configuration" path="/employee"/>
</flow>
```

MUnit テストの実行時に QA API エンドポイントからデータをコンシュームする手順は次のとおりです。

1. 検証を実行する各環境のプロパティファイルに HTTP 設定値を抽出します。それらのプロパティファイルは、​`src/main/resources`​ に置く必要があります。
    
    prod.properties
    
    ```xml
    http.host=dummy.restapiexample.com/api/v1/
    http.port=80
    ```
    
    qa.properties
    
    ```xml
    http.host=dummy.qax.restapiexample.com/api/v1/
    http.port=8081
    ```
    
    環境ごとにプロパティファイルを設定できます。
2. 以前作成したファイルから環境プロパティを読み込むには、設定ファイルの ​`configuration-properties`​ グローバル設定を使用します。
    
    ```xml
     <configuration-properties file="${mule-env}.properties"/>
    ```
3. HTTP 設定をプロパティファイル内で定義された変数に一致するプレースホルダーに置き換えます。
    
    ```xml
    <http:request-config name="HTTP_Request_configuration">
    	<http:request-connection host="${http.host}" port="${http.port}"/>
    </http:request-config>
    <flow name="requestApiFlow">
    	<http:request method="GET" config-ref="HTTP_Request_configuration" path="/employee"/>
    </flow>
    ```
4. MUnit Maven プラグインで環境変数を定義します。
    
    ```xml
     <configuration>
         ...
         <environmentVariables>
             <mule-env>qa</mule-env>
         </environmentVariables>
         ...
     </configuration>
    ```
    
    MUnit テストの実行中、MUnit は​`qa`​ プロパティファイルからプロパティを読み込み、テスト環境に接続します。