---
schema_version: "1"
id: 4e6fccf3d7804396caef40de94f790fd95a0017d0483474930fa08d2b8c9bc66
title: MUnit Maven プラグイン
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/munit/3.0/munit-maven-plugin.md
canonical_url: https://docs.mulesoft.com/jp/munit/3.0/munit-maven-plugin
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 421644a9b0ba66a55b55cf2bc07efe7cbad50a2107690c2f6b2e586210952c0e
description: MuleSoft Documentation Site
release: "3.0"
latest: false
---
# MUnit Maven プラグイン

MUnit には、継続的インテグレーション環境の一部として MUnit テストを実行できる Maven プラグインが用意されています。

Maven インストールの ​`pom.xml`​ または ​`settings.xml`​ ファイルへの次の設定は、Maven を介して MUnit を実行する場合のみ適用されます。

## [](#munit-maven-プラグインのセットアップ)MUnit Maven プラグインのセットアップ

このドキュメントは、pom.xml に ​`<munit.version>`​ プロパティがあることを前提とします。

- `pom.xml`​ ファイルで MUnit Maven プラグインを有効にする。
    
    MUnit Maven プラグイン
    
    ```xml
    <build>
      <plugins>
      ...
    
        <plugin>
          <groupId>com.mulesoft.munit.tools</groupId>
          <artifactId>munit-maven-plugin</artifactId>
          <version>${munit.version}</version>
          <executions>
            <execution>
              <id>test</id>
              <phase>test</phase>
              <goals>
                <goal>test</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
    
      ...
      </plugins>
    </build>
    ```
- `pom.xml`​ ファイルに MUnit 連動関係を追加する。
    
    連動関係
    
    ```xml
    <dependencies>
      ...
      <dependency>
        <groupId>com.mulesoft.munit</groupId>
        <artifactId>munit-runner</artifactId>
        <version>${munit.version}</version>
        <classifier>mule-plugin</classifier>
        <scope>test</scope>
      </dependency>
      <dependency>
        <groupId>com.mulesoft.munit</groupId>
        <artifactId>munit-tools</artifactId>
        <version>${munit.version}</version>
        <classifier>mule-plugin</classifier>
        <scope>test</scope>
      </dependency>
      ...
    </dependencies>
    ```
- MUnit 連動関係とプラグインのリポジトリを設定する。
    
    リポジトリ
    
    ```xml
    <repositories>
      <repository>
        <id>mulesoft-releases</id>
          <name>MuleSoft Releases Repository</name>
          <url>https://repository.mulesoft.org/releases/</url>
          <layout>default</layout>
        </repository>
    </repositories>
    ```
    
    プラグインリポジトリ
    
    ```xml
    <pluginRepositories>
      <pluginRepository>
        <id>mulesoft-release</id>
        <name>mulesoft release repository</name>
        <layout>default</layout>
        <url>https://repository.mulesoft.org/releases/</url>
        <snapshots>
          <enabled>false</enabled>
        </snapshots>
      </pluginRepository>
    </pluginRepositories>
    ```

MUnit には Surefire サポートが組み込まれています。 レポートは ​`target/surefire-reports`​ に出力されます。

### [](#親-pom-ファイルの処理)親 POM ファイルの処理

親 ​`pom.xml`​ ファイルで MUnit プラグインを宣言できます。このファイルの下位のすべての子プロジェクトはこの定義を参照できます。

親 - 子 POM リレーションで MUnit Maven プラグインを設定するには、親 ​`pom.xml`​ ファイルの ​`<pluginManagement>`​ セクションに MUnit プラグインの宣言を含めます。

次の例では、​`pirate-pom`​ プロジェクトは、そのプラグイン管理セクションで MUnit Maven プラグインを宣言し、この親の下位の各子が参照、上書き、または無視できるグローバル設定を定義しています。

```xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.1.0</modelVersion>

    <groupId>org.pirate</groupId>
    <artifactId>pirate-pom</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <properties>
        <munit.version>2.3.0</munit.version>
    </properties>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>com.mulesoft.munit.tools</groupId>
                    <artifactId>munit-maven-plugin</artifactId>
                    <version>${munit.version}</version>
                    <executions>
                        <execution>
                            <id>test</id>
                            <phase>test</phase>
                            <goals>
                                <goal>test</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                      <coverage>
                          <runCoverage>true</runCoverage>
                          <failBuild>false</failBuild>
                          <requiredApplicationCoverage>0</requiredApplicationCoverage>
                          <requiredResourceCoverage>0</requiredResourceCoverage>
                          <requiredFlowCoverage>0</requiredFlowCoverage>
                          <formats>
                              <format>console</format>
                              <format>html</format>
                          </formats>
                      </coverage>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>
```

### [](#親のプラグインの継承)親のプラグインの継承

子 ​`pom.xml`​ ファイルで MUnit プラグインを継承するには、そのプラグインを各子の POM ファイルの ​`<plugin>`​ セクションで個別に参照します。

次のサンプルでは、​`pirate-pom`​ ファイルをその親として参照し、次に ​`<plugin>`​ セクションで MUnit プラグインを宣言しています。MUnit プラグイン設定が親の POM ファイルの ​`<pluginManagement>`​ セクションから継承されるため、MUnit プラグインの ​`<version>`​ は指定されていません。

子の POM ファイルのサンプル

```xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <parent>
        <groupId>org.pirate</groupId>
        <artifactId>pirate-pom</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany</groupId>
    <artifactId>ninja</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>mule</packaging>
    <name>Mule ninja Application</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <app.runtime>4.1.4</app.runtime>
        <munit.version>2.3.0</munit.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>com.mulesoft.munit.tools</groupId>
                <artifactId>munit-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
```

### [](#親のプラグインの無視)親のプラグインの無視

親の ​`pom.xml`​ ファイルの下の各子プロジェクトで、親のプラグイン管理セクションで参照されているプラグインを無視し、そこで宣言されているプラグイン設定を実装しないように選択できます。

`<plugin>`​ セクションで Munit プラグインを宣言しないことで、​**pirate-pom**​ で宣言されたプラグインが継承されなくなります。

MUnit Maven プラグインを継承しない子の POM ファイル

```xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <parent>
        <groupId>org.pirate</groupId>
        <artifactId>pirate-pom</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany</groupId>
    <artifactId>ninja</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>mule</packaging>
    <name>Mule ninja Application</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <mule.version>4.1.0</mule.version>
        <munit.version>2.3.0</munit.version>
    </properties>

    <build>
        <plugins>
            <plugin>
            </plugin>
        </plugins>
    </build>
</project>
```

### [](#親のプラグインの上書き)親のプラグインの上書き

親の POM ファイルからプラグインを継承する場合、親の設定を上書きすることもできます。親の POM ファイルのプラグイン設定を上書きすると元の設定が抑制されるため、すべての必要な設定を再度宣言することが必要になります。

次の例では、親の POM ファイルのコンソールカバー率レポートを上書きし、HTML レポートに置き換えます。親の他の要素 (​`<failBuild>`​、​`<requiredApplicationCoverage>`​、​`<requiredResourceCoverage>`​、​`<requiredFlowCoverage>`​) の値が参照されていないため、この子ファイルはこれらの要素を継承せず、デフォルト値が適用されます。

親の POM ファイルでのカバー率設定

```xml
<coverage>
	<runCoverage>true</runCoverage>
	<failBuild>false</failBuild>
	<requiredApplicationCoverage>0</requiredApplicationCoverage>
	<requiredResourceCoverage>0</requiredResourceCoverage>
	<requiredFlowCoverage>0</requiredFlowCoverage>
	<formats>
		<format>console</format>
		<format>html</format>
	</formats>
</coverage>
```

カバー率レポートの形式を上書きする子の POM ファイル

```xml
<plugin>
	<groupId>com.mulesoft.munit.tools</groupId>
	<artifactId>munit-maven-plugin</artifactId>
	<configuration>
		<coverage>
			<runCoverage>true</runCoverage>
			<formats>
				<format>html</format>
			</formats>
		</coverage>
	</configuration>
</plugin>
```

## [](#カバー率のセットアップ)カバー率のセットアップ

次の設定は、Maven プラグインを使用して MUnit テストを実行する場合のみ適用されます。Studio からテストを実行する場合は適用されません。詳細は、​[「Maven でのカバー率の使用」](https://docs.mulesoft.com/jp/munit/3.0/coverage-maven-concept)​を参照してください。

MUnit 2.x 以降、カバー率レポートのゴールは Maven のレポートセクションと統合されています。カバー率レポートは、​`coverage-report`​ ゴール中の Maven の ​`site`​ ライフサイクル中に生成されます。

次の設定は、Maven プラグインを使用して MUnit テストを実行する場合のみ適用されます。Studio からテストを実行する場合は適用されません。  
Studio でカバー率レポートを実行するには、​[「Studio でのカバー率の使用」](https://docs.mulesoft.com/jp/munit/3.0/coverage-studio-concept)​を参照してください。

MUnit カバー率 - サンプル Maven 設定

```xml
<plugin>
    <groupId>com.mulesoft.munit.tools</groupId>
    <artifactId>munit-maven-plugin</artifactId>
    <version>${munit.version}</version>

    <executions>
        <execution>
            <id>test</id>
            <phase>test</phase>
            <goals>
                <goal>test</goal>
                <goal>coverage-report</goal>
            </goals>
        </execution>
    </executions>

    <configuration>
        <coverage>
            <runCoverage>true</runCoverage>
            <failBuild>false</failBuild>

            <requiredApplicationCoverage>75</requiredApplicationCoverage>
            <requiredResourceCoverage>50</requiredResourceCoverage>
            <requiredFlowCoverage>50</requiredFlowCoverage>

            <formats>
                <format>console</format>
                <format>html</format>
            </formats>
        </coverage>
    </configuration>
</plugin>
```

### [](#最小カバー率レベルのセットアップ)最小カバー率レベルのセットアップ

MUnit カバー率の機能の 1 つは、特定のカバー率レベルに到達しない場合にビルドを失敗させることです。

MUnit カバー率は 3 つの異なるレベルを処理します。

- **アプリケーション**​: すべてのアプリケーションの全体的なカバー率。
- **リソース**​: 個々の Mule 設定ファイルのカバー率レベル。
- **フロー**​: 各フローのイベントプロセッサーのカバー率。

必要なカバー率レベルを定義する方法は、次のとおりです。

MUnit カバー率 - 必要なカバー率

```xml
<coverage>
    <runCoverage>true</runCoverage>
    <failBuild>true</failBuild>

    <requiredApplicationCoverage>75</requiredApplicationCoverage> (1)
    <requiredResourceCoverage>50</requiredResourceCoverage>
    <requiredFlowCoverage>50</requiredFlowCoverage>
</coverage>
```

<table><tbody><tr><td><i class="conum" data-value="1"></i><b>1</b></td><td>各値はパーセントを表します。<br>パーセントが定義されていない場合はデフォルトで ​<strong>-1</strong>​ が設定され、そのレベルの要件が定義されていないことを示し、カバー率が低いためにビルドは失敗しません。</td></tr></tbody></table>

カバー率レベルを定義してプロパティ ​`failBuild`​ を ​**false**​ に設定し、レベルに到達していない場合、MUnit カバー率サマリーに警告が表示されます。

```console
===============================================================================
MUnit Coverage Summary
===============================================================================
 * Resources: 2 - Flows: 3 - Processors: 4
 * Application Coverage: 75.00%

----------------------------- WARNING --------------------------------------
 * Flow: file2.xml -> file2Flow1 coverage is below defined limit. Required: 50.0% - Current: 00.00% (1)
====================================================================================
```

<table><tbody><tr><td><i class="conum" data-value="1"></i><b>1</b></td><td>どのカバー率レベルが満たされていないか、カバー率レベルがどこで発生したかの詳細が示された警告。</td></tr></tbody></table>

### [](#フローまたはファイルの無視)フローまたはファイルの無視

もう 1 つの機能は、フローまたはファイルを無視する機能です。これにより、無視されたリソースには次が適用されます。

- カバー率データに含まれない。
- メッセージプロセッサーの総数には影響しない。
- フローがテストされていない場合、またはフローがカバー率メトリクスに到達していない場合でも、ビルドは失敗しない。

フローおよびファイルを無視する方法

MUnit カバー率 - フローとファイルの両方を無視

```xml
<coverage>
    <runCoverage>true</runCoverage>
    <failBuild>true</failBuild>

    <requiredApplicationCoverage>100</requiredApplicationCoverage>
    <requiredResourceCoverage>100</requiredResourceCoverage>
    <requiredFlowCoverage>100</requiredFlowCoverage>

    <ignoreFlows>
        <ignoreFlow>flow-1</ignoreFlow>
        <ignoreFlow>flow-2</ignoreFlow>
        ...
        <ignoreFlow>flow-n</ignoreFlow>
    </ignoreFlows>

    <ignoreFiles>
        <ignoreFile>mule-config-1.xml</ignoreFile>
        <ignoreFile>mule-config-2.xml</ignoreFile>
        ...
        <ignoreFile>mule-config-n.xml</ignoreFile>
    </ignoreFiles>
</coverage>
```

## [](#動的ポート)動的ポート

MUnit 2.2 以降では ​`dynamic-port`​ グローバル要素が導入されているため、MUnit スイートレベルで動的ポートを定義できます。次に説明されているプラグイン設定の代わりにこの要素を使用すると、Maven と Studio の両方から動的ポートを設定できます。  
この要素を設定する方法については、​[「動的ポート」](https://docs.mulesoft.com/jp/munit/3.0/dynamic-ports)​を参照してください。

継続的インテグレーション (CI) 環境で Mule アプリケーションをテストする場合、次のシナリオが発生することがあります。

Your application tries to open a specific port. The port is already in use. The application fails with a port binding exception.

MUnit Maven プラグインには、アプリケーションで空きポートを使用する機能が組み込まれています。

MUnit 動的ポートは、Mule アプリケーションのテストを開始する前に、バインドされていないポートを探して予約するよう MUnit Maven プラグインに指示します。選択された各ポートは、設定に示されている名前でシステムプロパティに配置されます。その後、アプリケーションはプレースホルダーを使用してポート番号を取得できます。

プラグインにより選択されるポートは、​`[40000,50000]`​ の範囲から取得されます。

<table>
<tbody><tr>
<td class="icon">
<i class="fa icon-caution" title="Caution"></i>
</td>
<td class="content">
<div class="paragraph">
<p>動的ポート機能は MUnit Maven プラグインの一部としてのみ使用できます。Anypoint Studio 内からテストを実行する場合、この機能は動作しません。</p>
</div>
</td>
</tr>
</tbody></table>

### [](#動的ポートの有効化)動的ポートの有効化

この機能を有効にするには、次のコードを MUnit Maven プラグインの ​`configuration`​ セクションに追加する必要があります。

動的ポートの設定

```xml
<plugins>
  <plugin>
    <groupId>com.mulesoft.munit.tools</groupId>
    <artifactId>munit-maven-plugin</artifactId>
    <configuration>
    ...
    <dynamicPorts>
      <dynamicPort>a.dynamic.port</dynamicPort>
    </dynamicPorts>
    ...
    </configuration>
  </plugin>
</plugins>
```

アプリケーションに ​`${http.port}`​ プレースホルダーが含まれる場合、設定は次のようになります。

例

```xml
<dynamicPorts>
  <dynamicPort>http.port</dynamicPort>
</dynamicPorts>
```

### [](#アプリケーションの準備)アプリケーションの準備

プレースホルダーでは、ポートを使用するアプリケーションの一部をパラメーター化する必要があります。たとえば、Mule アプリケーションに HTTP トラフィックをリスンさせるには、次の設定を指定します。

HTTP アプリケーション

```xml
<http:listener-config name="HTTP_Listener_config">
  <http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>

<flow name="httpFlow">
  <http:listener path="/" config-ref="HTTP_Listener_config"/>
</flow>
```

以前のアプリケーションはポート ​`8081`​ で常にリスンします。これを動的に行うには、次のように変更します。

動的ポートを使用する HTTP アプリケーション

```xml
<http:listener-config name="HTTP_Listener_config">
  <http:listener-connection host="0.0.0.0" port="${http.port}"/> (1)
</http:listener-config>

<flow name="httpFlow">
  <http:listener path="/" config-ref="HTTP_Listener_config"/>
</flow>
```

<table><tbody><tr><td><i class="conum" data-value="1"></i><b>1</b></td><td>プレースホルダー ​<code>${http.port}</code>​ に注意してください。</td></tr></tbody></table>

アプリケーションをこのようにコーディングし、動的ポートの設定を適用したら、アプリケーションは、開始する各実行で異なるポートをリスンします。

## [](#surefire-レポートの有効化)Surefire レポートの有効化

MUnit には Surefire のサポートが組み込まれています。追加の設定は必要ありませんが、必要でない場合はこれを無効にできます。

Surefire レポートの無効化

```none
<enableSurefireReports>false</enableSurefireReports>
```

レポートは ​`${project.build.directory}/surefire-reports`​ の下にあります。

デフォルトでは、これは ​`true`​ に設定されます。

## [](#sonar-レポートの有効化)SONAR レポートの有効化

MUnit では、​`enableSonarReports`​ のデフォルト設定である ​`true`​ で SonarQube を組み込みサポートしています。それ以上の設定は必要ありません。

このレポートは ​`${project.build.directory}/sonar-reports`​ にあります。

SONAR レポートが必要なければ無効化できます。

SONAR レポートの無効化

```none
<enableSonarReports>false</enableSonarReports>
```

レポートは ​`${project.build.directory}/sonar-reports`​ の下にあります。

デフォルトでは、これは ​`true`​ に設定されます。

## [](#プラグインを使用したテストの実行)プラグインを使用したテストの実行

### [](#mule-アプリケーションの-munit-テストの実行)Mule アプリケーションの MUnit テストの実行

単一リソース Mule プロジェクトで MUnit テストを実行します。

```none
mvn clean test
```

### [](#特定の-munit-テストスイートの実行)特定の MUnit テストスイートの実行

プロパティ ​`munit.test`​ を使用して、特定のテストスイートに属するテストのみを実行するように MUnit Maven プラグインに指示できます。

```maven
mvn clean test -Dmunit.test=<regex-test-suite>
```

このパスは、​`src/test/munit`​ に対して相対的です。

プロパティ ​`munit.test`​ は、正規表現に対応しています。この式は、MUnit テストスイートファイルの名前に適用されます。正規表現の言語は Java 実装です。  

次に例を示します。

```console
mvn clean test -Dmunit.test=.*my-test.*
```

この機能を利用するには、命名規則を MUnit テストスイートに追加します。

### [](#特定の-munit-テストの実行)特定の MUnit テストの実行

1 つのテストスイートを実行するように MUnit に指示する場合と同じ方法で、テストスイート内の特定のテストを実行するように MUnit を設定できます。テスト名を追加するには、プロパティ ​`munit.test`​ に特殊文字 ​`#`​ を追加して使用する必要があります。

```console
mvn clean test -Dmunit.test=<regex-test-suite>#<regex-test-name>
```

これも、正規表現に対応しています。式は、MUnit テストの属性 ​`name`​ に適用されます。次に例を示します。

```console
mvn clean test -Dmunit.test=.*my-test.*#.*test-scenario-1.*
```

正規表現に一致しない MUnit テストスイート内のテストは、​**ignored**​ フラグが設定されます。

`pom.xml`​ 設定からこれを設定することもできます。

```xml
<plugins>
  <plugin>
      <groupId>com.mulesoft.munit.tools</groupId>
      <artifactId>munit-maven-plugin</artifactId>
      <configuration>
      ...
      <munitTest>example-MunitTest-suite.xml</munitTest>
      ...
    </configuration>
  </plugin>
</plugins>
```

### [](#特定のタグを使用したテストの実行)特定のタグを使用したテストの実行

1 つの特定のタグでグループ化したテストのみを実行できます。

```console
mvn clean test -Dmunit.tags=<munit-tag>
```

`pom.xml`​ 設定からこれを設定することもできます。

```xml
<plugins>
  <plugin>
      <groupId>com.mulesoft.munit.tools</groupId>
      <artifactId>munit-maven-plugin</artifactId>
      <configuration>
      ...
      <munitTags>exampleMunitTag</munitTags>
      ...
    </configuration>
  </plugin>
</plugins>
```

複数のタグをカンマで区切って指定できます。

### [](#すべてのテストをスキップ)すべてのテストをスキップ

MUnit は Maven と同じメカニズムを利用します。テストをスキップするには、​`skipTests`​ パラメーターを使用する必要があります。

テストのスキップの例

```console
mvn clean package -DskipTests
```

`pom.xml`​ 設定からこれを設定することもできます。

```xml
<plugins>
  <plugin>
      <groupId>com.mulesoft.munit.tools</groupId>
      <artifactId>munit-maven-plugin</artifactId>
      <configuration>
      ...
      <skipMunitTests>true</skipMunitTests>
      ...
    </configuration>
  </plugin>
</plugins>
```

### [](#1-つのスイートが失敗した場合にテストをスキップ)1 つのスイートが失敗した場合にテストをスキップ

MUnit では、1 つのテストスイートが失敗した場合に残りのテストをスキップすることができます。

```xml
<plugins>
  <plugin>
      <groupId>com.mulesoft.munit.tools</groupId>
      <artifactId>munit-maven-plugin</artifactId>
      <configuration>
      ...
      <skipAfterFailure>true</skipAfterFailure>
      ...
    </configuration>
  </plugin>
</plugins>
```

指定しない場合、この値はデフォルトで ​`false`​ になります。

## [](#specify-runtime-product)ランタイム製品の指定

テストするアプリケーションをどのランタイムの種別で実行するかを指定できます。可能な値:

- `MULE`​: Community Edition の場合。
- `MULE_EE`​: Enterprise Edition の場合。

```xml
<plugins>
  <plugin>
    <groupId>com.mulesoft.munit.tools</groupId>
    <artifactId>munit-maven-plugin</artifactId>
    <configuration>
      ...
      <runtimeProduct>MULE</runtimeProduct>
      ...
    </configuration>
  </plugin>
</plugins>
```

### [](#ランタイム製品バージョンの指定)ランタイム製品バージョンの指定

MUnit では、テストするアプリケーションをどのランタイムバージョンで実行するかを指定できます。

```xml
<plugins>
  <plugin>
    <groupId>com.mulesoft.munit.tools</groupId>
    <artifactId>munit-maven-plugin</artifactId>
    <configuration>
      ...
      <runtimeVersion>4.2.2</runtimeVersion>
      ...
    </configuration>
  </plugin>
</plugins>
```

## [](#jvm-の指定)JVM の指定

テストするアプリケーションをどの JVM (または Java 実行可能ファイル) で実行するかを指定できます。​`munit.jvm`​ パラメーターに実行可能ファイルへのパスを入力する必要があります。

JVM の指定

```console
mvn clean package -Dmunit.jvm=/path/to/jdk/bin/java
```

`pom.xml`​ 設定からこれを設定することもできます。

```xml
<plugins>
  <plugin>
    <groupId>com.mulesoft.munit.tools</groupId>
    <artifactId>munit-maven-plugin</artifactId>
    <configuration>
      ...
      <jvm>/path/to/jdk/bin/java</jvm>
      ...
    </configuration>
  </plugin>
</plugins>
```

### [](#追加の引数行)追加の引数行

JVM に追加の引数行を渡すことができます。各引数を個別の ​`argLine`​ で指定します。

引数行

```xml
<plugins>
  <plugin>
    <groupId>com.mulesoft.munit.tools</groupId>
    <artifactId>munit-maven-plugin</artifactId>
    <configuration>
      ...
      <argLines>
          <argLine>-XX:MaxPermSize=512m</argLine>
          <argLine>-Xmx1024m</argLine>
      </argLines>
      ...
    </configuration>
  </plugin>
</plugins>
```

### [](#環境変数)環境変数

テスト実行時に追加の環境変数を設定するには、各環境変数をそれぞれのキーと値を使用して指定できます。

追加の環境変数

```xml
<plugins>
  <plugin>
    <groupId>com.mulesoft.munit.tools</groupId>
    <artifactId>munit-maven-plugin</artifactId>
    <configuration>
      ...
      <environmentVariables>
        <MY_ENV>exampleValue</MY_ENV>
        <MY_OTHER_ENV>val2</MY_OTHER_ENV>
      </environmentVariables>
      ...
    </configuration>
  </plugin>
</plugins>
```

前の例に示されているように、環境変数を使用して、​`${MY_ENV}`​ などのプレースホルダーを置き換えることができます。

### [](#システムプロパティ変数)システムプロパティ変数

MUnit テストを正常に実行するために、特定のシステム変数の定義が必要な場合があります。

システムプロパティ変数の設定

```xml
<plugins>
  <plugin>
    <groupId>com.mulesoft.munit.tools</groupId>
    <artifactId>munit-maven-plugin</artifactId>
    <configuration>
      ...
      <systemPropertyVariables>
        <my.property.key>my.property.value</my.property.key>
      </systemPropertyVariables>
      ...
    </configuration>
  </plugin>
</plugins>
```

実行コンテキストに応じて、システムプロパティの値が変わる場合があります。このようなプロパティを参照する場合、その値を上書きしてテストの再現性を強化することをお勧めします。

これを行うには、Maven を使用して MUnit を実行するときに ­​`-D`​ 引数を使用できます。 ​`-D`​ 引数と共に渡された変数は、他のどのプロパティよりも優先されます。次に例を示します。

```none
-Dmy.property.key=my.property.another.value
```

## [](#ファイルへのテスト出力のリダイレクト)ファイルへのテスト出力のリダイレクト

複数のテストを実行すると、ビルド出力が非常に複雑になり、読みづらくなる可能性があります。各テストスイートの出力をファイルにリダイレクトできます。これにより、テスト結果のみがビルド出力に残ります。それぞれのファイルで、各テストスイートの標準出力を確認できます。

これらのファイルは ​`testOutputDirectory`​ フォルダーに、​`munit.${suiteName}-output.txt`​ の命名規則に従って配置されます。​`suiteName`​ は MUnit テストフォルダーを基準とする XML ファイルの相対的な名前を表します。

特定のスイートに属さないテストの出力は、ビルド出力をクリーンな状態に維持するため印刷されませんが、Maven をデバッグモードで実行することで、これを有効にできます。

各テストスイートの出力をファイルにリダイレクトする方法

ファイルへのテスト出力のリダイレクト

```xml
<plugins>
  <plugin>
    <groupId>com.mulesoft.munit.tools</groupId>
    <artifactId>munit-maven-plugin</artifactId>
    <configuration>
      ...
      <redirectTestOutputToFile>true</redirectTestOutputToFile>
      ...
    </configuration>
  </plugin>
</plugins>
```

デフォルトでは、これは ​`false`​ に設定されます。

### [](#テスト出力ディレクトリ)テスト出力ディレクトリ

テスト出力ファイルを作成する場所を選択できます。指定するパスを絶対パスとしたり、Maven プレースホルダーとして記述したりできます。

絶対パスを使用したテスト出力ディレクトリ

```xml
<plugins>
  <plugin>
    <groupId>com.mulesoft.munit.tools</groupId>
    <artifactId>munit-maven-plugin</artifactId>
    <configuration>
      ...
      <testOutputDirectory>/my/absolute/path</testOutputDirectory>
      ...
    </configuration>
  </plugin>
</plugins>
```

Maven プレースホルダーを使用したテスト出力ディレクトリ

```xml
<testOutputDirectory>${project.build.directory}/my/output/folder</testOutputDirectory>
```

デフォルトでは、ファイルは ​`${project.build.directory}/munit-reports/output/`​ に作成されます。

## [](#munit-maven-プラグイン設定リファレンス)MUnit Maven プラグイン設定リファレンス

MUnit Maven プラグインでは、一連の省略可能なパラメーターを設定できます。

<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 1. Maven プラグインパラメーター</caption>
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 22.2222%;">
<col style="width: 44.4445%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名前</th>
<th class="tableblock halign-center valign-top">型</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>argLines</code></p>
</div></div></td>
<td class="tableblock halign-center valign-top"><div class="content"><div class="paragraph">
<p>List</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>テスト実行で設定する追加の JVM 引数行。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>coverage</code></p>
</div></div></td>
<td class="tableblock halign-center valign-top"><div class="content"><div class="paragraph">
<p>設定</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>テスト実行で設定されるカバー率設定。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>dynamicPorts</code></p>
</div></div></td>
<td class="tableblock halign-center valign-top"><div class="content"><div class="paragraph">
<p>List</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>テスト実行で設定される動的ポート。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>enableSurefireReports</code></p>
</div></div></td>
<td class="tableblock halign-center valign-top"><div class="content"><div class="paragraph">
<p>boolean (ブール)</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>surefire 形式で MUnit テストの結果を生成するには、値を ​<code>true</code>​ に設定します。<br>
デフォルト値: <code>true</code>​</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>munitTest</code></p>
</div></div></td>
<td class="tableblock halign-center valign-top"><div class="content"><div class="paragraph">
<p>String (文字列)</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>実行する MUnit の名前。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>munitTags</code></p>
</div></div></td>
<td class="tableblock halign-center valign-top"><div class="content"><div class="paragraph">
<p>String (文字列)</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>MUnit タグの名前。これらの名前でタグ付けされたテストのみが実行されます。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>skipMunitTests</code></p>
</div></div></td>
<td class="tableblock halign-center valign-top"><div class="content"><div class="paragraph">
<p>boolean (ブール)</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>すべての MUnit テストをスキップする場合、​<code>true</code>​ に設定します。<br>
デフォルト値: <code>false</code>​</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>skipAfterFailure</code></p>
</div></div></td>
<td class="tableblock halign-center valign-top"><div class="content"><div class="paragraph">
<p>boolean (ブール)</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>1 つのテストが失敗すると、すべてのテストがスキップされます。<br>
デフォルト値: <code>false</code>​</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>munitTestsDirectory</code></p>
</div></div></td>
<td class="tableblock halign-center valign-top"><div class="content"><div class="paragraph">
<p>File (ファイル)</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>MUnit テストが保存されているディレクトリ。<br>
デフォルト値: <code>${project.build.directory}/test-mule/munit</code>​</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>runtimeVersion</code></p>
</div></div></td>
<td class="tableblock halign-center valign-top"><div class="content"><div class="paragraph">
<p>String (文字列)</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Mule Runtime のバージョン<br>
Maven からテストを実行する場合、この値は ​<code>mule-artifact.json</code>​ ファイルの ​<code>minMuleVersion</code>​ パラメーターから取得されます。<br>
Studio での MUnit テストの実行に使用する Mule Runtime バージョンを変更するには、​<a href="https://docs.mulesoft.com/jp/munit/3.0/runtime-patching#studio" class="xref page">「Studio を使用して MUnit にパッチを適用する」</a>​を参照してください。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>runtimeProduct</p>
</div></div></td>
<td class="tableblock halign-center valign-top"><div class="content"><div class="paragraph">
<p>String (文字列)</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Runtime の種別。使用できる値は次のとおりです。</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>MULE</code>​: Community Edition の場合。</p>
</li>
<li>
<p><code>MULE_EE</code>​: Enterprise Edition の場合。</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>デフォルトでは、この値は ​<code>mule-artifact.json</code>​ ファイルの ​<code>requiredProduct</code>​ パラメーターから取得されます。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>jvm</code></p>
</div></div></td>
<td class="tableblock halign-center valign-top"><div class="content"><div class="paragraph">
<p>String (文字列)</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>使用する JVM (または Java 実行可能ファイルへのパス) を指定するオプション。</p>
</div>
<div class="paragraph">
<p>デフォルトでは、JVM は Maven の実行に使用される VM と同じです。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>environmentVariables</code></p>
</div></div></td>
<td class="tableblock halign-center valign-top"><div class="content"><div class="paragraph">
<p>Map (マップ)</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>テスト実行で設定される追加の環境変数。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>redirectTestOutputToFile</code></p>
</div></div></td>
<td class="tableblock halign-center valign-top"><div class="content"><div class="paragraph">
<p>boolean (ブール)</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>MUnit テストの標準出力をファイルにリダイレクトするには、値を ​<code>true</code>​ に設定します。<br>
デフォルト値: <code>false</code>​</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>systemPropertyVariables</code></p>
</div></div></td>
<td class="tableblock halign-center valign-top"><div class="content"><div class="paragraph">
<p>Map (マップ)</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>テスト実行で設定されるシステムプロパティ。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>testOutputDirectory</code></p>
</div></div></td>
<td class="tableblock halign-center valign-top"><div class="content"><div class="paragraph">
<p>ファイル</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>テスト出力が書き込まれるディレクトリ。<br>
デフォルト値: <code>${project.build.directory}/munit-reports/output/</code>​</p>
</div></div></td>
</tr>
</tbody>
</table>