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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

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

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Best Practices for Creating Highly Reliable Applications in Mule 4
  • Handle HL7 MLLP Messages With Mule 4
  • MuleSoft Integration With RabbitMQ
  • MuleSoft APIkit Router - QueryParam and Header Strict Validation Configuration

Trending

  • Chaos Engineering for Microservices
  • SQL Server Index Optimization Strategies: Best Practices with Ola Hallengren’s Scripts
  • Analyzing “java.lang.OutOfMemoryError: Failed to create a thread” Error
  • How to Convert Between PDF and TIFF in Java
  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.

By 
Jitendra Bafna user avatar
Jitendra Bafna
DZone Core CORE ·
Apr. 18, 17 · Tutorial
Likes (8)
Comment
Save
Tweet
Share
36.9K 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.

Related

  • Best Practices for Creating Highly Reliable Applications in Mule 4
  • Handle HL7 MLLP Messages With Mule 4
  • MuleSoft Integration With RabbitMQ
  • MuleSoft APIkit Router - QueryParam and Header Strict Validation Configuration

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!