4. Speakers
Piyush Kumari
● Working as Senior Consultant at InvenioLSI.
● Approx 7 years of Total Experience.
● 6+ years experience in Mulesoft.
● Certified MuleSoft Developer.
6. What is Munit?
● Best Automated testing app in Anypoint Studio.
● Integrated with Anypoint studio, allow you to create, design and run Munits just like you
would mule application.
● Provides full coverage of code.
● Integrated with Maven and surefire with integrations with continuous deployment
environment.
7. With MUnits you can ?
Munits proves below features:
● Create you test cases by writing Mule code.
● Mock Processors(Http Requester, SAP Connector, ApiKit Router etc.)
● Spy on any processor
● Parameterized test cases based on types.
● Do end to end or particular at sub-flow level of testing.
● Check coverage in studio
● Get Coverage Reports.
9. Munit operations:
● Before Suite: runs before executing Munit Test Suite
The MUnit Before Suite contains code that is meant to be executed before the whole suite.
The Before Suite has one execution rule: Run before all the tests, just once.
For example, suppose you have an MUnit Test Suite file with four tests. The code inside an
MUnit Before Suite runs just once, before your four tests
● After Suite:
The MUnit After Suite is a scope. It can contain code that is meant to be executed after the
whole suite. The After suite has one execution rule: Run after all the tests, just once.
For instance, let’s suppose you have an MUnit Test Suite File with four tests. The code
inside an MUnit After Suite, runs just once, after all your tests.
10. Munit operations:
● Before Test: runs BEFORE executing Munit Test.
The MUnit Before Test Scope contains code that is meant to be executed before each test. Each
Before Test scope follows the same execution rule: Run before each test.
● After Test: runs AFTER executing Munit Test.
The MUnit After Test Scope contains code that is meant to be executed after each test. Each After
Test scope follows the same execution rule: Run after each test.
● Test: adds a new test.
● Set Event: to set the initial payload to be supplied.
● Set null Payload: defines null payload for testing.
11. Munit Tools operations:
● Assert: validate mule event content.
○ Equals
○ Expression
○ That
● Mock When: mock event processor when it matches the
defined name and attributes.
● Spy: what happens when before/after event processor is
called.
● Verify Call: verify if the processor was called.
● Fail: allow you to fail you test case on purpose.
12. Various ways to create munit tests:
Method 1: File>New>MUnit Test
13. Various ways to create munit tests:
Method 2: Pallet Test Operation
14. Various ways to create munit tests:
Method 3: From Flow
Result: XML Creation and munit test suite
15. MUnit Tests Scope:
Behaviour Scope:
- Set all the conditions before executing test logic
- Mock and spy goes into this section
Execution scope:
- This is meant for testing the logic which will wait for all the processes to get completed before
executing the next scope.
- Runs flow through this section only.
Validation Scope:
- This is meant to have all the validations regarding the result of execution scope.
- Assert and verify comes here to validate and verify the flow.
17. Set Event:
● Allows you to set payload,attributes and
variables.
● Normally defined at the beginning of munit test
to define the first message to set.
● You can define as many properties required for
you flow.
18. Assert That:
● Allows you to run assertions to validate the stats of event
content.
● Uses DataWeave function MUnit matchers to define the
conditions for any value in expression.
● Include the prefix MunitTool:: in the expression
○ notNullValue() checks that the expression is not null.
■ #[MunitTools::nullValue()]
20. Mock When:
Allows you to Mock an event processor when it matches the
defined name and attributes.
1. Pick Processor
2. Choose Target Processor
3. Select attributes(specific doc:name)
4. Click OK
21. Mock When:
Configure “Then Return “ Section:
● Then Return is defined to set the response which
we expect from the mocked processor.
● The response can be Payload, Variable, Attribute
or even an error.
1. Choose Type of response
2. Click Add Icon
3. Define Response
4. Click OK
22. SPY: Work as detective to check when happens
before and after the processor.
1. Pick Processor
2. Choose Target Processor
3. Select attributes(specific
doc:name)
4. Click OK
23. Verify Call: Allows you to verify is that particular processor
was called or not.
24. ● Defining one test suite and then multiple test cases inside with multiple Munit:Test
Ways to write Munit Test Suite:
25. ● Parametrizations:
Parameterization in munits allows you to run single test
with multiple cases(inputs and outputs).
PROS:
Developers can effectively cover
various logical flows without having
to write dedicated test flows for each
such logical flow
CONS:
Application will get deployed exactly
the number of parameterized test
cases written.
3(parametrization case) → 3 times
application will deploy.
26. ● Basic Info:
1. To run single Munit from terminal:
i. mvn clean /munit test name/ -Dmunit.test=XYZ.xml#testName
2. Ignore particular flow or file from munit coverage:
<coverage>
<ignoreFlows>
<ignoreFlow>flow-name</ignoreFlow>
</ignoreFlows>
</coverage>
3. To run API skipping munits in local:
Maven clean package/mvn clean install -DskipTests