2. 2
● About me
● What is unit testing / MUnit
● Basic MUnit components for unit testing
● Demo
● Questions
Agenda
3. 3
● Senior MuleSoft Developer
● MuleSoft Ambassadress & Meetup Leader
● 5x MuleSoft Certified
● 3+ years using MuleSoft
● Evangelist at Women Who Code Monterrey
● Founder and Content Creator at ProstDev
About me
4. 4
● Type of Software Testing to verify that your code works as expected.
● Create code to test your code
What is unit testing?
UNIT TEST # A PLUS B ACTUAL C EXPECTED C TEST
PASSED?
1 0 PLUS 1 1 1
5. 5
● Type of Software Testing to verify that your code works as expected.
● Create code to test your code
What is unit testing?
UNIT TEST # A PLUS B ACTUAL C EXPECTED C TEST
PASSED?
1 0 PLUS 1 1 1
2 87 PLUS 20 107 107
6. 6
● Type of Software Testing to verify that your code works as expected.
● Create code to test your code
What is unit testing?
UNIT TEST # A PLUS B ACTUAL C EXPECTED C TEST
PASSED?
1 0 PLUS 1 1 1
2 87 PLUS 20 107 107
3 -2 PLUS -2 4 -4
7. 7
● MuleSoft’s framework to create Unit Tests for Mule flows.
● Drag-and-drop / visual components.
● FAIL / PASS visual results.
What is MUnit?
8. 8
● Better quality code
● Final user is happy
● Other developers are happy
● Less time spent fixing bugs after release
● Less budget spent on bug fixes
● Final user is happy
● Other developers are happy
● Project/Delivery/Product Managers are happy
Why do we want to test our code?
11. 11
● Set a new Mule Event
● Payload
● Attributes
● Error
● Variables
Set Event
Error
12. 12
Set Event: Example
Error
Set a new Mule Event containing this payload:
Set Event
and containing a variable called isActive set to true.
13. 13
1) Mock when <processor>
2) Then return <Mule Event>
“Imagine that when we try to call that,
we get this Mule Event.”
Mock when
Error
14. 14
1) Mock when <processor>
2) Then return <Mule Event>
“Imagine that when we try to call Salesforce
via HTTP, we get this JSON payload.”
Mock when: Example
Error
1) Mock when processor’s name is “HTTP Request to
Salesforce”
2) Then return a new Mule Event containing this
payload:
Mock when
15. 15
● Assert equals
● Assert that
● Assert expression
”Let’s make sure that this is equal to that.”
“Let’s make sure that this is not empty.”
“Let’s make sure that this is more than that.”
Assert
Error
16. 16
● Assert that
”Let’s make sure that the payload
is equal to this JSON object.”
If they are equal, the test passed.
If not, it failed.
Assert: Example
Error
Assert that the actual payload
is equal to this JSON object:
Assert that
Is this true?
18. Continue learning
GitHub Repository:
https://github.com/alexandramartinez/vampireAPI
Knowledge check!
1. Take a look at how the MUnit test is built
2. Remove the MUnit test suite
3. Try to build it again!
4. (Optional) Add more tests/validations
Documentation:
● MUnit Event Processors: https://docs.mulesoft.com/munit/2.3/event-processors
● Set Event: https://docs.mulesoft.com/munit/2.3/set-event-processor
● Mock When: https://docs.mulesoft.com/munit/2.3/mock-event-processor
● Assert That: https://docs.mulesoft.com/munit/2.3/assertion-event-processor