DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. MUnit Testing With Mulesoft: Part I

MUnit Testing With Mulesoft: Part I

In this walkthrough, learn how to build automated tests for your Mule integrations and APIs with MUnit, integrated with Anypoint Studio.

Jitendra Bafna user avatar by
Jitendra Bafna
CORE ·
Apr. 18, 17 · Tutorial
Like (8)
Save
Tweet
Share
34.86K Views

Join the DZone community and get the full member experience.

Join For Free

MUnit is a Mule application testing framework which allows you to build automated tests for your Mule integrations and API's. MUnit is very well integrated with Anypoint Studio.

Various features available with Mule MUnit:

  • Create and build Mule tests by writing Mule code.

  • Create and build Mule tests by writing Java code.

  • Verify Message Processor calls.

  • Mock Message Processor.

  • Mock outbound endpoints.

  • Disable outbound endpoints.

  • Disable flow inbound connectors.

  • Disable inbound endpoints.

  • Debug the tests.

  • View coverage reports.

  • Various asserts available like Assert Equals, Assert Not Equals, Assert Payload, Assert False, Assert True, Assert Null Payload, Assert Not Null Payload.

  • Spy Message Processor.

In this article, we will see how to create and run the MUnit tests.

First, you want to make sure MUnit is installed in your Anypoint Studio. In case it is not installed, follow below steps.

Go to Help > Install New Software...

Image title

Now, it will open new pop-up windows. Select MUnit Update Site from drop down list. Check MUnit and MUnit Tools for Mule.

Image title


Finally, just click Next and accept the license terms and conditions. Click Finish and it will install MUnit tools in your Anypoint Studio.

How To Create the MUnit Tests for Mule Flow

For creating MUnit tests for your application, right click on the flow select MUnit > Create New MUnit.

Image title

It will create MUnit tests for the flow and it will be available in folder src/test/unit.

In Assert Payload, you need to define Expected Value and in this case, it will be payload. Also, provide Test Failure Message, in case the value doesn't message the expected value then it will provide the failure message you have defined.

Image title

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:munit="http://www.mulesoft.org/schema/mule/munit" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/munit http://www.mulesoft.org/schema/mule/munit/current/mule-munit.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">
    <munit:config name="munit" doc:name="MUnit configuration"/>
    <spring:beans>
        <spring:import resource="classpath:message-demo-filter.xml"/>
    </spring:beans>

    <munit:test name="message-demo-filter-test-suite-message-demo-filterFlowTest" description="Test">
        <set-payload value="#['The cat is brown and clever']" doc:name="Set Payload"/>
        <flow-ref name="message-demo-filterFlow" doc:name="Flow-ref to message-demo-filterFlow"/>
        <munit:assert-payload-equals message="Output message is not matching expected value #[payload]" expectedValue="#[payload]" doc:name="Assert Payload"/>
    </munit:test>
</mule>


Run MUnit Tests

For running the MUnit tests, right click in the canvas region of the MUnit test flow and select Run MUnit suite.

Image titleAfter running the MUnit suite, it will provide details like errors, failures (if any), coverage report, and test status.

Image title

In above image, the green color means that your test case has been successfully executed and passed.

Now, you know how to create MUnit tests for your flow.

Below is the video tutorial:


Testing MuleSoft

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Type Variance in Java and Kotlin
  • Why Every Fintech Company Needs DevOps
  • PostgreSQL: Bulk Loading Data With Node.js and Sequelize
  • Top Five Tools for AI-based Test Automation

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: