MUnit Matchers

Jyoti Nimbalkar
3 min readMay 20, 2023

--

After reading this blog you will be able to,
— Make use of Assert that processor and various Matchers associated with it.

Why MUnit?

MUnit is a Mule application testing framework that allows us to easily build automated tests for our integrations and APIs. MuleSoft provides us a full suite of integration and unit test capabilities.

MUnit Event Processors

MUnit provides a set of event processors to assert, validate and mock the content and status of the mule event.

In this blog we will learn various MUnit matchers available under MUnit Assert that Processor.

Refer to this link to read more about MUnit assert connectors.

Assert That

This is one of the Munit processors that contains set of MUnit matchers to define the assertion conditions for any value in an expression.

All the Munit matchers are segregated into 5 major categories as listed below.

· Core matchers

· String matchers

· Comparable matchers

· Iterable and Map matchers

· Resource Matchers

Core matchers:

null value: Validates that if the value is null.

Not null value: Validates if the value is not null.

More Core Matchers…

String Matchers

containsString(String): Validates if the expression has the specified String.

startsWith(String): Validates if the expression starts the specified String.

More String Matchers…

Comparable matchers:

greaterThan(Comparable): Validates that the expression is greater than the specified value.

greaterThanOrEqualTo(Comparable): Validates that the expression is greater than or equal to the specified value.

More Comparable Matchers…

Iterable and Map matchers:

everyItem(Matcher): Checks that every element in the expression matches the specified matcher.

hasItem(Object): Validates if any element in the expression matches the specified matcher.

More Iterable and Map matchers:

Resource Matchers:

getResourceAsStream(String): This Matcher Returns the resource from the path String as a stream.

getResourceAsReusableStream(String):Returns the resource from the path String as a reusable stream

More Resource Matchers:

— — — — — — — — — — — — — — Blog Ends Here — — — — — — — — — — — — — -

References:

· https://docs.mulesoft.com/munit/2.3/event-processors

· https://medium.com/@jnimbalkar777/munit-different-types-of-munit-assertions-1f5ffdf957fb

· https://www.mulesoft.com/

· https://medium.com/@jnimbalkar777/munit-testing-mule-application-using-munit-part-i-c14266c0104a

· https://medium.com/@jnimbalkar777/munit-automate-munit-test-case-creation-using-api-specification-5d9d32f05334

--

--

Jyoti Nimbalkar

MuleSoft Ambassador | Meetup Leader|Certified MuleSoft Developer and Architect | Staff Engineer @Nagarro| https://www.linkedin.com/in/jyoti-nimbalkar-868656154/