---
schema_version: "1"
id: 682583499c8383d3e0ecce9c325a33e975ead29e4f3668fb66b59b43ea70c91d
title: Maven Configuration for Coverage
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/munit/3.6/coverage-maven-concept.md
canonical_url: https://docs.mulesoft.com/munit/3.6/coverage-maven-concept
source_site: docs.mulesoft.com
content_type: documentation
content_hash: ff1aac66de4a12956342d0e17c01b8b13eca42860da5ded6a8eacf8bb13584c4
description: MuleSoft Documentation Site
release: "3.6"
latest: false
---
---
product: MUnit
version: 3.6
---

# Maven Configuration for Coverage

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

![logo acb active](/mulesoft/current/en-us/_/img/icons/anypoint-code-builder.svg "Anypoint Code Builder")Anypoint Code
Builder

![logo studio active](/mulesoft/current/en-us/_/img/icons/studio.svg "Anypoint Studio")Anypoint Studio

From MUnit 2.x and later, the coverage report goal is integrated with the Maven reporting section.
MUnit generates coverage reports during the Maven `site` lifecycle, during the `coverage-report`
goal.

The following configurations apply if you execute your MUnit tests using the Maven plugin. They
don’t apply when running tests from Anypoint Code Builder or Anypoint Studio.

MUnit Coverage - Sample Maven configuration

```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>
```

## Coverage Report Types

When you enable MUnit Coverage, the console displays a summary report.

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

MUnit Coverage offers four types of reports:

- Console report  
  The console report prints in the console. It works with the summary report and shows an overview
  of the MUnit run, with a count of all resources, flows, and processors, as well as the overall
  application coverage level, and warnings and errors if any.

- HTML report  
  The HTML report shows the same information as the console report but is formatted to fit any web
  browser. It’s available in the `${application.path}/target/site/munit/coverage/` path.

- JSON report  
  The JSON report provides the same information as the HTML report but in a JSON format. It’s
  available at `${application.path}/target/site/munit/coverage/munit-coverage.json`.

- SONAR report  
  The SONAR report shows the same information as the HTML report, in a SonarQube format.

To enable the report generation, add the following configuration:

MUnit Coverage - Report Configuration

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

    <formats>
        <format>console</format> (1)
        <format>html</format>    (2)
        <format>json</format>    (3)
        <format>sonar</format>   (4)
    </formats>
</coverage>
```

<table><tbody><tr><td><i data-value="1"></i><b>1</b></td><td>Console report</td></tr><tr><td><i data-value="2"></i><b>2</b></td><td>HTML report</td></tr><tr><td><i data-value="3"></i><b>3</b></td><td>JSON report</td></tr><tr><td><i data-value="4"></i><b>4</b></td><td>SONAR report</td></tr></tbody></table>

You can choose to have either none, one, or all the report types added to your configuration.

To configure, for example, the JSON report generation, add the following configuration to your
`pom.xml` file:

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

    <formats>
        <format>json</format>
    </formats>
</coverage>
```

## Set up a Minimum Coverage Level

One of the features of MUnit Coverage is to fail the build if a certain coverage level isn’t
reached.

MUnit Coverage handles three different levels:

- **Application**: The overall coverage of all your application.

- **Resource**: The coverage level of each Mule configuration file.

- **Flow**: The coverage of event processors in each flow.

To define the required coverage levels:

MUnit Coverage - Require Coverage

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

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

<table><tbody><tr><td><i data-value="1"></i><b>1</b></td><td>Each value represents a percentage.<br>If a percentage isn’t defined, it defaults to <strong>-1</strong>, which sets no requirements for said level so the build doesn’t fail due to low coverage.</td></tr></tbody></table>

If you define coverage levels but set the property `failBuild` to `false`, and then the levels
aren’t reached, a warning shows up in the MUnit Coverage summary:

```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 data-value="1"></i><b>1</b></td><td>Warning detailing which coverage level isn’t met, and where it happens.</td></tr></tbody></table>

## Ignore a Flow or a File

You can also ignore a flow or a file. This way, the ignored resource:

- Does not count as coverage data.

- Does not affect the overall number of message processors.

- Does not cause a build to fail if the flow isn’t tested or if the flow doesn’t reach coverage
  metrics.

To ignore flows and files:

MUnit Coverage - Ignore flows and files

```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>
```

## See Also

- [Coverage Report](https://docs.mulesoft.com/munit/3.6/munit-coverage-report)

- [Using Coverage in Studio](https://docs.mulesoft.com/munit/3.6/coverage-studio-concept).
