Contact Us 1-800-596-4880

Testing Your Mule Projects with MUnit

Create, run, and modify, MUnit tests for your Mule projects in Anypoint Studio with MUnit. MUnit is a MuleSoft unit testing framework for creating and running unit tests on a Mule application, as described in MUnit Overview.

In the MUnit windows, you can find information about your tests:

  • Errors

  • Failures

  • Results

  • Coverage

Get to Know MUnit Tests

You can perform the following tasks with MUnit in Studio:

  • Create a test

  • Create a test suite

  • Run a test

  • Debug your project

  • Fix errors

  • Generate test reports

When you work with your MUnit tests in Studio, you can:

  • Find the test of your project in the src/test/munit folder, in Package Explorer.

  • Drag components to your test from the Mule Palette, in Message Flow.

  • Define the MUnit configuration for your tests from Global Elements.

  • Review test XML files from Configuration XML.

Create MUnit Tests and MUnit Test Suits

To create an MUnit test:

  1. Open your Mule project in Studio.

  2. Right-click on the src/test/munit folder, or create this folder if it doesn’t exist in your Mule project.

  3. Select New > MUnit Test.

  4. In the MUnit test suite window, write a name for your test suite.

  5. Select the flows to test from the list of flows available in your project.

  6. Click Finish.

You can also configure MUnit tests and test suites from the XML editor.

Run MUnit Tests

You can run MUnit test in different ways in Studio:

  • Right-click on your MUnit test suite file and select MUnit > Run Test.

  • In Message Flow, right-click on your test flow, and select Run MUnit suite.

When you run a test, Studio creates a build and displays the progress and the result of the test in the Console tab and the MUnit window. If all tests execute successfully, the build succeeds. If there is an error, the build fails.

Run MUnit Tests in Debug Mode

You can run your MUnit tests in debug mode to step through your code, inspect variables, and understand the flow of your Mule application.

  1. Open your Mule project in Studio.

  2. In the src/test/munit folder, open the MUnit test suite to debug.

  3. In Message Flow, add a breakpoint by right-clicking on the element that must have the breakpoint.

  4. Right-click on your MUnit flow test and select Debug MUnit test.

Enable Flow Sources

The Enable Flow Sources element within the MUnit test tells MUnit which flow sources to load and execute for the test. By default, MUnit doesn’t start the event sources (flow sources such as triggers and listeners).

You can define flow sources with the Mule Properties view of your MUnit test in Studio:

  1. Click Add.

  2. Select the name of the flow from Name of the flow.

Learn more about flow sources in MUnit docs (Enable Flow Sources) and configure which flow sources must start for your tests.