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 Video Library
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
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

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Microservices Testing: Key Strategies and Tools
  • The Twelve-Factor App and WSO2 Micro Integrator
  • Why Incorporate CI/CD Pipeline in Your SDLC?
  • Build and Deploy a Node.js Application into Azure Web Apps Using Azure DevOps (CI/CD)

Trending

  • What Technical Skills Can You Expect To Gain From a DevOps Course Syllabus?
  • How To Learn Secure Software Development Lifecycle (SDLC)
  • How To Simplify Multi-Cluster Istio Service Mesh Using Admiral
  • AWS Amplify: A Comprehensive Guide
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. Leveraging MUnit for Test Automation

Leveraging MUnit for Test Automation

A key CI and CD capability of any enterprise solution is a testing framework to write and run repeatable tests. MUnit has tons of test automation capabilities.

Prashant Joshi user avatar by
Prashant Joshi
·
Jan. 25, 17 · Tutorial
Like (2)
Save
Tweet
Share
4.45K Views

Join the DZone community and get the full member experience.

Join For Free

Traditional integration platforms could get away with providing some command line tools to automate the build and deployment of applications built on their platform. However, in the modern world, integration platforms need to encompass the critical API management and cloud components, as well, so the scope of Continuous Integration and Continuous Delivery tools are no longer just limited to integration applications only. This also requires support for provisioning integration software and applications in private or public cloud platforms and capability to automate governance of deployed applications. 

A key CI and CD capability of any enterprise solution is a testing framework to write and run repeatable tests, so in this article, we will focus on the test automation capabilities of the platform provided by MUnit.

MUnit is a Mule application testing framework that allows you to easily build automated tests for your integrations and APIs. It provides a full suite of integration and unit test capabilities and is fully integrated with Maven and Surefire for integration with your continuous deployment environment. 

With MUnit, you can:

  • Create your Mule test by writing Mule or Java code, and disable flow inbound endpoints and endpoint connectors.
  • Mock outbound endpoints and message processors.
  • Spy any message processor and verify message processor calls.
  • Create unit and integration tests in a local environment (MUnit allows you to start a local FTP/SFTP, DB server, or mail server).
  • Call the Mule client from Mule code and assert flow exceptions.
  • Enable or disable particular tests, and see assertion and error reports with Mule stack trace.
  • Extend the MUnit framework with plugins.
  • Check visual coverage and debug your tests with Studio.

Here is a quick example of how to test an existing application developed in another how-to series blog.

1. Download the Existing HowTo Project

Click here to download. Set up the prerequisites as instructed in the readme and exchange documentation for executing the project.

2. Import the Existing Project Into a New Workspace

Use Anypoint Studio. Save as devops-howto_1.0.0.

Munit-1

Munit-2

3. Make Sure the Project Points to JRE

It needs to point to JRE on the local machine as shown below (File > Properties > Java Build Path).

Munit-3

4. Install MUnit 

If not already installed, install MUnit (Help > Install New Software).

Munit-4

5. Create a New Test Suite

Once MUnit is installed, right-click on the project and create a new test suite. The test suite is created in the src/test/munit folder.

Munit-5

Munit-6

The test flow in the new test-suite already has reference to the soap-on-db service to be invoked. Add a Set Message processor before the invocation to set the input payload as required to invoke the service. Copy the payload string from the /src/test/resources/SetMessage.xml file into the payload field as shown below.

Munit-7

6. Store the Response From the Web Service

Use Object to String and Set Property processors to store the response from the web service.

Munit-8

7. Set the Expected Response

Use the Transform Message processor. Copy the response from /src/test/resources/ExpectedSOAPResponse.xml and ensure that the response is enclosed within single quotes.

Munit-9

8. Store the Expected Response 

Store the expected response in a property as shown below.

Munit-10

9. Compare the Actual and Expected Response 

Use the Assert Equals message processor to compare the actual and expected response. If the responses do not match, the assertion will throw the configured exception in the generated report.

Munit-11

10. Select and Run the Test Suite

Munit-12

A test report is generated in the MUnit tab with a green bar indicating that the test executed successfully. Green checkmarks against the message processors in the web service flow indicate all processors that were tested as part of the flow.

Munit-14

11. Simulate an Error Report 

To simulate an error report, modify the expected response as below in the Expected Response processor. Change the loan ID to 101.

Image title

The error report generated would then indicate the difference between expected and actual response, marking the test as a failure.    

Munit-16

 To save time, you can also download the preconfigured MUnit project from Anypoint Exchange and execute the above tests.

To summarize, MUnit is fully integrated with Anypoint Studio and provides a simple easy-to-use graphical interface to develop, debug, and check coverage of test cases. It provides a full suite of unit and integration test capabilities and is fully integrated with Maven and Surefire ensuring comprehensive support for DevOps CI/CD processes. For a complete list and details around MUnit's capabilities, refer to the MUnit documentation.

unit test Continuous Integration/Deployment Test automation Integration Test suite Web Service application

Published at DZone with permission of Prashant Joshi. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Microservices Testing: Key Strategies and Tools
  • The Twelve-Factor App and WSO2 Micro Integrator
  • Why Incorporate CI/CD Pipeline in Your SDLC?
  • Build and Deploy a Node.js Application into Azure Web Apps Using Azure DevOps (CI/CD)

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

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

Let's be friends: