[12th July 2020]: [MUnit Testing made easier in Mule]
FARIDABAD India, Mulesoft Group
#MulesoftMeetup #FaridabadMulesoft @FaridaMulesoft @mulesoft
All contents © MuleSoft Inc.
Agenda
2
• Introduction
• MuleSoft for Beginners
• MUnit Testing made easier in Mule
• Fun Quiz ( Win certification voucher )
• Networking
• Next Event Announcement
#MulesoftMeetup #FaridabadMulesoft @FaridaMulesoft @mulesoft
All contents © MuleSoft Inc.
Organizers
3
Welcome everyone! Thanks for joining us!
All contents © MuleSoft Inc.
Surprises!
4
• Participate in an online
Quiz to win the
instructor-led training
classes and certification
exam vouchers. (3
Winners!)
• Be geared up for the
quiz sessions at the end

Start your Mulesoft Journey
Mulesoft for beginners
#MulesoftMeetup #FaridabadMulesoft @FaridaMulesoft @mulesoft
All contents © MuleSoft Inc. 6
• https://training.mulesoft.com/
• https://www.youtube.com/channel/UCHQ5feaAtOCEtis453_RYAg
(Tech Lightning) YouTube Channel
• https://www.youtube.com/c/SFDCPanther YouTubeChannel
• https://docs.mulesoft.com/general/
Resources
#MulesoftMeetup #FaridabadMulesoft @FaridaMulesoft @mulesoft
All contents © MuleSoft Inc.
Speaker
7#MulesoftMeetup #FaridabadMulesoft @FaridaMulesoft @mulesoft
What’s new in MUnit?
Easier MUnit testing in
Mule
All contents © MuleSoft Inc.
What will we be talking about?
9#MulesoftMeetup #FaridabadMulesoft @FaridaMulesoft @mulesoft
All contents © MuleSoft Inc. 10
• MUnit is the Mule application testing framework that enables developers to create,
design, and run unit and integration tests on Mule applications created within Anypoint
Studio.
• It natively supports unit and integration testing on APIs and Mule apps in local and
CI/CD environments (via Maven).
Note: If this is your first time learning about MUnit, check out our tutorial on how to create your first MUnit
test in Anypoint Studio.
• Further we will learn how the MUnit test recorder works and how it can simplify the
testing process.
• The test recorder allows us to create tests for our application without the need of
writing any code, empowering us to build more robust applications and ensure their
quality to meet any test coverage requirements.
What is MUnit and Test Recorder?
All contents © MuleSoft Inc.
What is MUnit?
11
MUnit is divided into two
main sub-modules, one is
called MUnit and the other
MUnit Tools. Additionally,
there are Utilities available
for import such as a
Database Server, FTP
Server, or a Run and Wait
Scope. Here is an overview
of some of the different
MUnit features that you
can implement into your
unit testing.
All contents © MuleSoft Inc. 12
How do you use MUnit?
• Use MUnit to build
test flows (technically
called test suites in
the industry) focused
on executing Mule
flows. Each test is
essentially a Mule
flow.
• Use components from
MUnit and generic
Mule components to
build test flows.
• Test flows execute in
a Mule runtime and
report results.
1
2
3
All contents © MuleSoft Inc. 13
• A test flow is broken down into three sections:
1. Execution,
2. Behavior and
3. Validation.
• The behavior scope sets all the preconditions before executing the
test logic. The execution scope contains the testing logic which will
wait for all processes to finish before executing the next scope. The
validation scope contains all the validations for the results of the
execution scope.
How do you use MUnit?
All contents © MuleSoft Inc. 14
• Test: Creates a new test “flow” broken down into three sections: Execution, Behavior, and Validation. The
behavior scope sets all the preconditions before executing the test logic. The execution scope contains the
testing logic which will wait for all processes to finish before executing the next scope. The validation scope
contains all the validations for the results of the execution scope.
• Set Event: Allows you to define a Mule Event. Usually used at the beginning of an MUnit test to define the
first message to send to the flow being tested.
• Set null payload: Defines a null payload to test how your flow will handle a null value.
• After Suite: Runs after executing all of the MUnit tests and runs 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
of your tests.
• After Test: Runs after executing an MUnit test. For instance, let’s suppose you have an MUnit Test Suite file
with four tests. The code inside an MUnit After Test runs after each of your four tests; it runs four times.
• Before Suite: Runs before executing all of the MUnit tests and runs 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 all
of your four tests.
• Before Test: Runs before executing an MUnit test. For instance, let’s suppose you have an MUnit Test Suite
file with four tests. The code inside an MUnit Before test runs before each of your four tests; it runs four
times.
MUnit Operations:
All contents © MuleSoft Inc. 15
• Assert That: Allows you to run assertions to validate the state of a Mule event, such as checking to see
if a payload equals a certain value.
• Fail: Useful in validating that a test should fail if that point is reached in the flow. The processor throws
a java.lang.AssertionError.
• Mock When: Use this processor to mock an event, such as sending a mock POST request with a
mocked payload.
• Run Custom: Allows you to assert the Mule event content against a custom assertion.
• Verify Call: Allows you to verify if a processor was called.
• Spy: Allows you to see what happens before and after an event processor is called in your Flow.
Usually, you will tell the Spy processor to run a set of instructions before and after the execution.
MUnit Tools:
All contents © MuleSoft Inc. 16
Head-to-head comparison vs. legacy middleware
All contents © MuleSoft Inc. 17
The pain of testing today
#MulesoftMeetup #FaridabadMulesoft @FaridaMulesoft @mulesoft
All contents © MuleSoft Inc. 18
Munit test recorder
Let us quickly go through a tutorial on how to record a test and generate a flow.
https://developer.mulesoft.com/tutorials-and-howtos/quick-start/getting-started-with-
the-munit-test-recorder
All contents © MuleSoft Inc. 19
Generally available from April 30th 2020
• Automate test creation: Capture flow
execution with the new Munit test
recorder to automatically generate
tests.
• Scale with confidence: Leverage
runtime performance improvements for
more efficient code execution.
• Collaborate on API Specs: Pull and
update API specifications within Studio
and merge them back to Design Center.
Anypoint Studio 7.5 and Mule 4.3
#MulesoftMeetup #FaridabadMulesoft @FaridaMulesoft @mulesoft
All contents © MuleSoft Inc.
Where to go next?
20#MulesoftMeetup #FaridabadMulesoft @FaridaMulesoft @mulesoft
Q & A
Quiz Time
All contents © MuleSoft Inc.
Take a stand !
23
• Nominate yourself for the
next meetup speaker and
suggest a topic as well.
• Either for our virtual meetup
speaker, or in-person
meetup speaker.
• Surprise swag for upcoming
Speakers.
• Fill this form -
https://bit.ly/speakar
All contents © MuleSoft Inc.
What’s next
24
• Share:
– Tweet/share in LinkedIn , facebook, Instagram with your pictures with the hashtag
#FaridabadMuleMeetup #MuleSoftMeetup
– Also use #BringMuleSoftConnectToFaridabad to reach our wish to MuleSoft 
– Invite your network to join: https://meetups.mulesoft.com/Faridabad/
• Feedback:
– Please fill out the slips with details like are you new to Mule? If so what technology you are
currently working , What makes you to think of adopting MuleSoft and what topic you are
expecting in future Meetups
– Contact MuleSoft at meetup@mulesoft.com for ways to improve the program
– Your Feedback is Food for us. https://bit.ly/f-mf
• Our next meetup:
– Date: TBD
– Location: Faridabad/Virtual
– Topic: TBD
THANK YOU 
#Everyone
for becoming a part of such a great
#community.
Mule Testing in Mulesfoft 4.X

Mule Testing in Mulesfoft 4.X

  • 1.
    [12th July 2020]:[MUnit Testing made easier in Mule] FARIDABAD India, Mulesoft Group #MulesoftMeetup #FaridabadMulesoft @FaridaMulesoft @mulesoft
  • 2.
    All contents ©MuleSoft Inc. Agenda 2 • Introduction • MuleSoft for Beginners • MUnit Testing made easier in Mule • Fun Quiz ( Win certification voucher ) • Networking • Next Event Announcement #MulesoftMeetup #FaridabadMulesoft @FaridaMulesoft @mulesoft
  • 3.
    All contents ©MuleSoft Inc. Organizers 3 Welcome everyone! Thanks for joining us!
  • 4.
    All contents ©MuleSoft Inc. Surprises! 4 • Participate in an online Quiz to win the instructor-led training classes and certification exam vouchers. (3 Winners!) • Be geared up for the quiz sessions at the end 
  • 5.
    Start your MulesoftJourney Mulesoft for beginners #MulesoftMeetup #FaridabadMulesoft @FaridaMulesoft @mulesoft
  • 6.
    All contents ©MuleSoft Inc. 6 • https://training.mulesoft.com/ • https://www.youtube.com/channel/UCHQ5feaAtOCEtis453_RYAg (Tech Lightning) YouTube Channel • https://www.youtube.com/c/SFDCPanther YouTubeChannel • https://docs.mulesoft.com/general/ Resources #MulesoftMeetup #FaridabadMulesoft @FaridaMulesoft @mulesoft
  • 7.
    All contents ©MuleSoft Inc. Speaker 7#MulesoftMeetup #FaridabadMulesoft @FaridaMulesoft @mulesoft
  • 8.
    What’s new inMUnit? Easier MUnit testing in Mule
  • 9.
    All contents ©MuleSoft Inc. What will we be talking about? 9#MulesoftMeetup #FaridabadMulesoft @FaridaMulesoft @mulesoft
  • 10.
    All contents ©MuleSoft Inc. 10 • MUnit is the Mule application testing framework that enables developers to create, design, and run unit and integration tests on Mule applications created within Anypoint Studio. • It natively supports unit and integration testing on APIs and Mule apps in local and CI/CD environments (via Maven). Note: If this is your first time learning about MUnit, check out our tutorial on how to create your first MUnit test in Anypoint Studio. • Further we will learn how the MUnit test recorder works and how it can simplify the testing process. • The test recorder allows us to create tests for our application without the need of writing any code, empowering us to build more robust applications and ensure their quality to meet any test coverage requirements. What is MUnit and Test Recorder?
  • 11.
    All contents ©MuleSoft Inc. What is MUnit? 11 MUnit is divided into two main sub-modules, one is called MUnit and the other MUnit Tools. Additionally, there are Utilities available for import such as a Database Server, FTP Server, or a Run and Wait Scope. Here is an overview of some of the different MUnit features that you can implement into your unit testing.
  • 12.
    All contents ©MuleSoft Inc. 12 How do you use MUnit? • Use MUnit to build test flows (technically called test suites in the industry) focused on executing Mule flows. Each test is essentially a Mule flow. • Use components from MUnit and generic Mule components to build test flows. • Test flows execute in a Mule runtime and report results. 1 2 3
  • 13.
    All contents ©MuleSoft Inc. 13 • A test flow is broken down into three sections: 1. Execution, 2. Behavior and 3. Validation. • The behavior scope sets all the preconditions before executing the test logic. The execution scope contains the testing logic which will wait for all processes to finish before executing the next scope. The validation scope contains all the validations for the results of the execution scope. How do you use MUnit?
  • 14.
    All contents ©MuleSoft Inc. 14 • Test: Creates a new test “flow” broken down into three sections: Execution, Behavior, and Validation. The behavior scope sets all the preconditions before executing the test logic. The execution scope contains the testing logic which will wait for all processes to finish before executing the next scope. The validation scope contains all the validations for the results of the execution scope. • Set Event: Allows you to define a Mule Event. Usually used at the beginning of an MUnit test to define the first message to send to the flow being tested. • Set null payload: Defines a null payload to test how your flow will handle a null value. • After Suite: Runs after executing all of the MUnit tests and runs 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 of your tests. • After Test: Runs after executing an MUnit test. For instance, let’s suppose you have an MUnit Test Suite file with four tests. The code inside an MUnit After Test runs after each of your four tests; it runs four times. • Before Suite: Runs before executing all of the MUnit tests and runs 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 all of your four tests. • Before Test: Runs before executing an MUnit test. For instance, let’s suppose you have an MUnit Test Suite file with four tests. The code inside an MUnit Before test runs before each of your four tests; it runs four times. MUnit Operations:
  • 15.
    All contents ©MuleSoft Inc. 15 • Assert That: Allows you to run assertions to validate the state of a Mule event, such as checking to see if a payload equals a certain value. • Fail: Useful in validating that a test should fail if that point is reached in the flow. The processor throws a java.lang.AssertionError. • Mock When: Use this processor to mock an event, such as sending a mock POST request with a mocked payload. • Run Custom: Allows you to assert the Mule event content against a custom assertion. • Verify Call: Allows you to verify if a processor was called. • Spy: Allows you to see what happens before and after an event processor is called in your Flow. Usually, you will tell the Spy processor to run a set of instructions before and after the execution. MUnit Tools:
  • 16.
    All contents ©MuleSoft Inc. 16 Head-to-head comparison vs. legacy middleware
  • 17.
    All contents ©MuleSoft Inc. 17 The pain of testing today #MulesoftMeetup #FaridabadMulesoft @FaridaMulesoft @mulesoft
  • 18.
    All contents ©MuleSoft Inc. 18 Munit test recorder Let us quickly go through a tutorial on how to record a test and generate a flow. https://developer.mulesoft.com/tutorials-and-howtos/quick-start/getting-started-with- the-munit-test-recorder
  • 19.
    All contents ©MuleSoft Inc. 19 Generally available from April 30th 2020 • Automate test creation: Capture flow execution with the new Munit test recorder to automatically generate tests. • Scale with confidence: Leverage runtime performance improvements for more efficient code execution. • Collaborate on API Specs: Pull and update API specifications within Studio and merge them back to Design Center. Anypoint Studio 7.5 and Mule 4.3 #MulesoftMeetup #FaridabadMulesoft @FaridaMulesoft @mulesoft
  • 20.
    All contents ©MuleSoft Inc. Where to go next? 20#MulesoftMeetup #FaridabadMulesoft @FaridaMulesoft @mulesoft
  • 21.
  • 22.
  • 23.
    All contents ©MuleSoft Inc. Take a stand ! 23 • Nominate yourself for the next meetup speaker and suggest a topic as well. • Either for our virtual meetup speaker, or in-person meetup speaker. • Surprise swag for upcoming Speakers. • Fill this form - https://bit.ly/speakar
  • 24.
    All contents ©MuleSoft Inc. What’s next 24 • Share: – Tweet/share in LinkedIn , facebook, Instagram with your pictures with the hashtag #FaridabadMuleMeetup #MuleSoftMeetup – Also use #BringMuleSoftConnectToFaridabad to reach our wish to MuleSoft  – Invite your network to join: https://meetups.mulesoft.com/Faridabad/ • Feedback: – Please fill out the slips with details like are you new to Mule? If so what technology you are currently working , What makes you to think of adopting MuleSoft and what topic you are expecting in future Meetups – Contact MuleSoft at meetup@mulesoft.com for ways to improve the program – Your Feedback is Food for us. https://bit.ly/f-mf • Our next meetup: – Date: TBD – Location: Faridabad/Virtual – Topic: TBD
  • 25.
    THANK YOU  #Everyone forbecoming a part of such a great #community.