---
schema_version: "1"
id: e3d4097a1c229f8630730fa711942f8573a5bc54315acb01531ba4337adcfbec
title: MUnit Parameterized Test Suites
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/munit/latest/parameterized.md
canonical_url: https://docs.mulesoft.com/munit/latest/parameterized
source_site: docs.mulesoft.com
content_type: documentation
content_hash: f0a04ee381e0c03b2ef0d7da10cff751d061a8db16a289e69d9fcb527019790f
description: MuleSoft Documentation Site
release: "3.7"
latest: true
---
---
product: MUnit
version: 3.7
is-latest-version: true
keywords: munit, testing, unit testing
---

# MUnit Parameterized Test Suites

> 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

MUnit parameterized test suites run the same tests multiple times with different input values,
reducing duplication in your test code. Define parameterizations inline in the test suite
configuration or load them from a YAML file in your project’s test resources.

The test suite parameterization is defined at a configuration level as follows:

```xml
<munit:config>
    <munit:parameterizations>
        <munit:parameterization name="firstParameterization">
            <munit:parameters>
                <munit:parameter propertyName="name" value="Robert"/>
                <munit:parameter propertyName="lastname" value="Plant"/>
            </munit:parameters>
        </munit:parameterization>
        <munit:parameterization name="secondParameterization">
            <munit:parameters>
                <munit:parameter propertyName="name" value="Jimmy"/>
                <munit:parameter propertyName="lastname" value="Page"/>
            </munit:parameters>
        </munit:parameterization>
    </munit:parameterizations>
</munit:config>
```

The Test Suite runs twice: Firstly, with the `firstParameterization` parameters. Secondly, with the
`secondParameterization` parameters.

For example, if you have a test that sets a payload for a flow and expects a result:

Parameterization Example

```xml
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:munit="http://www.mulesoft.org/schema/mule/munit"
      xmlns:munit-tools="http://www.mulesoft.org/schema/mule/munit-tools"
      xsi:schemaLocation="
        http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
        http://www.mulesoft.org/schema/mule/munit http://www.mulesoft.org/schema/mule/munit/current/mule-munit.xsd
        http://www.mulesoft.org/schema/mule/munit-tools http://www.mulesoft.org/schema/mule/munit-tools/current/mule-munit-tools.xsd">

    <munit:config name="parameterized-test.xml">
        <munit:parameterizations>
            <munit:parameterization name="sumThree">
                <munit:parameters>
                    <munit:parameter propertyName="input" value="#[1]"/>
                    <munit:parameter propertyName="output" value="#[2]"/>
                </munit:parameters>
            </munit:parameterization>
            <munit:parameterization name="sumFive">
                <munit:parameters>
                    <munit:parameter propertyName="input" value="#[2]"/>
                    <munit:parameter propertyName="output" value="#[4]"/>
                </munit:parameters>
            </munit:parameterization>
        </munit:parameterizations>
    </munit:config>

    <munit:test name="expectFlowResult">
        <munit:behavior>
            <set-payload value="${input}"/>
        </munit:behavior>
        <munit:execution >
            <flow-ref name="myFlow"/>
        </munit:execution>
        <munit:validation>
            <munit-tools:assert-equals actual="#[payload]" expected="${output}" />
        </munit:validation>
    </munit:test>

</mule>
```

## Access Parameters from DataWeave

Use the DataWeave `p()` function to access parameter values inside DataWeave expressions,
concatenate parameter values with other strings, perform comparisons or calculations, and use
parameters in complex DataWeave transformations.

Using the parameterization from the first example, the following test uses `p()` to build a greeting
message and validate that the payload contains the expected name:

Accessing Parameters with the p() Function

```xml
<munit:test name="validateGreeting">
    <munit:behavior>
        <set-payload value="#['Hello, ' ++ p('name') ++ ' ' ++ p('lastname')]"/>
    </munit:behavior>
    <munit:validation>
        <munit-tools:assert-that
          expression="#[payload contains p('name')]"
          is="#[MunitTools::equalTo(true)]"/>
    </munit:validation>
</munit:test>
```

## Parameterization from File

To use the same parameterized values on different test suites, you must save your parameterizations
values in a YAML file in the `/test/resources` directory of your Mule application project:

parameterizations.yaml Example

```yaml
firstParameterization:
  name: "Robert"
  lastname: "Plant"

secondParameterization:
  name: "Jimmy"
  lastname: "Page"
```

And reference it from your test suite configuration:

Example Parameterization From File

```xml
<munit:config>
    <munit:parameterizations file="parameterizations.yaml" />
</munit:config>
```

You can combine both methods to add parameterized values to a test suite:

Example Parameterization From File and in the Test Suite Configuration

```xml
<munit:config name="parameterization-from-file-test.xml">
    <munit:parameterizations file="parameterizations.yaml" >
        <munit:parameterization name="thirdParameterization">
            <munit:parameters>
                <munit:parameter propertyName="name" value="John"/>
                <munit:parameter propertyName="lastname" value="Bonham"/>
            </munit:parameters>
        </munit:parameterization>
    </munit:parameterizations>
</munit:config>
```

If you define the same parameterization key in a YAML file and your test suite configuration, the
test suite parameterization overrides your YAML parameterization.

## See Also

- [DataWeave Function: p(propertyName: String): String](https://docs.mulesoft.com/dataweave/latest/dw-mule-functions-p)
