Nav
You are viewing an older version of this section. Click here to navigate to the latest version.

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:


               
            
1
2
<munit.version>1.3.0</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

         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<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

          
       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<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

          
       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<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

          
       
1
2
3
4
5
6
7
8
<repositories>
  <repository>
    <id>mulesoft-releases</id>
      <name>MuleSoft Releases Repository</name>
      <url>http://repository.mulesoft.org/releases/</url>
      <layout>default</layout>
    </repository>
</repositories>

You also need to add the Plugin repository.

Plugin Repositories

          
       
1
2
3
4
5
6
7
8
9
10
11
<pluginRepositories>
  <pluginRepository>
    <id>mulesoft-release</id>
    <name>mulesoft release repository</name>
    <layout>default</layout>
    <url>http://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.