Contact Us 1-800-596-4880

MUnit Maven Support

MUnit provides a Maven plugin that allows you to run your MUnit tests as part of your continuous integration environment.

Basic Setup

Setting Up Your pom.xml File

MUnit is a composition of several modules, all of which are necessary to run your MUnit test. Maven offers as much flexibility as possible.

For MUnit to run properly with Maven, you need to add a few sections to your pom.xml file.

If you are using Anypoint Studio, Maven integration is already solved for you. See Using Maven in Anypoint Studio for details.

This documentation assumes you have the <munit.version> and <mule.munit.support.version> properties in your pom.xml.
For example:

<munit.version>1.3.5</munit.version>
<mule.munit.support.version>3.7.5</mule.munit.support.version>

Do not combine MUnit modules of different versions. That is, the munit.version should be the same across all MUnit artifacts in your pom.xml, like the plugin or the runner.

Regarding the Mule MUnit support module, the mule.munit.support.version should match the mule.version. For example, 3.7.0 version of the support module would be compatible with 3.7.0, 3.7.1, 3.7.2 and other versions of Mule, but not necessarily with 3.6.0.

MUnit Maven Plugin

The MUnit Maven Plugin allows you to run MUnit tests from Maven. To enable the plugin, add the following section to your pom.xml.

MUnit Maven Plugin
<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>

To learn how to configure the plugin, follow our Maven Plugin configuration guide.
Usage specifics can be found at the MUnit Maven Plugin documentation.

MUnit Folder

All the MUnit Test Suite files reside in src/test/munit. You need to tell Maven to add this folder to the classpath.

MUnit Folder
<build>
...

  <testResources>
    <testResource>
      <directory>src/test/munit</directory>      (1)
    </testResource>
    <testResource>
      <directory>src/test/resources</directory>  (2)
    </testResource>
  </testResources>

...
</build>
1 The actual MUnit test folder.
2 The normal resources folder, usually used to store other files.

MUnit Dependencies

Listed below are the minimal artifacts required to enable MUnit to run from Maven.

MUnit Dependencies
<dependencies>
...

  <dependency>
    <groupId>com.mulesoft.munit</groupId>
    <artifactId>mule-munit-support</artifactId>
    <version>${mule.munit.support.version}</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>com.mulesoft.munit</groupId>
    <artifactId>munit-runner</artifactId>
    <version>${munit.version}</version>
    <scope>test</scope>
  </dependency>

...
</dependencies>

MUnit Repositories

MUnit artifacts are deployed in the Mule Maven repositories, which you’ve probably seen before.

Repositories
<repositories>
  <repository>
    <id>mulesoft-releases</id>
      <name>MuleSoft Releases Repository</name>
      <url>https://repository.mulesoft.org/releases/</url>
      <layout>default</layout>
    </repository>
</repositories>

You also need to add the Plugin repository.

Plugin Repositories
<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>
If you code your MUnit tests in Java, you don’t need the MUnit Maven Plugin nor the plugin repository.

Surefire Support

MUnit has Surefire support built in. No additional configuration is needed.

The reports can be found under target/surefire-reports.