4. Agenda
● Why application testing is important?
● MuleSoft testing framework - MUnit
● Implement Unit Testing Strategies using MUnit Tools
● MUnit Coverage
● Demo – MUnit Test Recorder
● API Led Connectivity and SEDA
6. Why application testing is important?
● We all make mistakes.
● Gives confidence to developers and customers to ensure good quality product is delivered.
● Untested code is broken code.
● Executable documentation of code’s behaviour.
7. Unit Testing
● White-box testing.
● Verifies the functionality of a specific unit.
● Do not require deployment into any special environment, such as a staging environment.
8. MUnit
● MUnit, is a dedicated unit testing tool specifically targeted to testing Mule applications inside a
Mule runtime.
● Design and create white-box test cases as Mule flows.
● Each test is itself a Mule flow, using components from the MUnit and MUnit Tools modules.
9. MUnit cont. . .
● Test Flow Structure ● Test Tags
● Test Coverage
10. Implement Unit Testing Strategies
using Munit Tools
● For read-only interactions to any
dependencies (such as other APIs): allowed
to invoke production endpoints ("sociable"
unit tests).
● For write interactions: developers must
implement mocks using MUnit.
● Assertions about the result are tested and
recorded.
11. MUnit Coverage
● Runs only for EE edition runtimes.
● Measurement of how much of a Mule application has been executed by a set of MUnit tests
by counting the amount of event processors executed.
● Enable MUnit Coverage
1. Maven
2. Studio
● MUnit Coverage Reports
1. Console
2. HTML
3. JSON
4. Sonar
12. MUnit Coverage Metrics
Flows Subflows Batch
jobs
XML
XML
XML
XML
XML
Application overall coverage
metrics
Resource coverage
metrics
Flow coverage metrics
17. 17
• Order data in eCommerce system
• Inventory data in SAP
• Customer data in SAP, Salesforce
Project objective: Web app provides
real-time order status and order
history for sales team engaging with
customers
Aggregated customer
data
Order status Order history
Web app API
A common project-based Approach
18. 18
Web app API
Aggregated customer
data
Order status Order history
On time and within budget
Limited opportunity for reuse
Tight coupling = brittleness
Difficult to govern
Meets business requirements
?
A common project-based Approach
20. 20
• Discoverable and accessible
through self-service
• Productized and designed for
ease of consumption
• Easily managed for security,
scalability, and performance
Modern
API
Modern API- The core enabler of new model
26. 26
SEDA Architecture
Staged, Event-Driven Architecture:
● The architecture upon which Mule was built
● Decouples receiving, processing, and dispatching phase Manage streams and
larger-than-memory payloads transparently
● Supports higher levels of parallelism in specific stages of processing
● Allows for more-specific tuning of areas within a flow's architecture
28. 28
SEDA Architecture
Staged, Event-Driven Architecture:
Scenario 1:
Inbound Connector is one way
Outbound Connector is one way
No transaction Flow
PROS CONS
Uses SEDA model with three fully decoupled
stages
Flow cannot return a response to the caller
Highly Performant Complicates integration with client that need
a response
29. 29
SEDA Architecture
Scenario 2: Synchronous - Asynchronous mode
Receiver thread is exchange pattern
Dispatcher thread is one-way
PROS CONS
Returns the component response to the
caller
Receiver thread pool can be still
overwhelmed by incoming requests
Dispatching decoupled from receiving and
servicing
Receiver
Synchronous
Flow Dispatcher
Asynchronous
30. 30
SEDA Architecture
Scenario 3: Synchronous mode
PROS CONS
Uses SEDA model with three fully decoupled
stages
All load handled by the connector’s receiver
threads
Simple to implement Don’t use SEDA queueing
Receiver
Synchronous
Flow Dispatcher
synchronous
31. 31
SEDA Architecture
Scenario 4: Asynchronous - Synchronous mode
PROS CONS
Allow synchronous routing in the dispatcher Flow cannot return a response to the caller
Receiving decoupled from dispatching and
receiving
Flow thread pool size constrains the
outbound dispatching load capacity
Receiver
Asynchronous
Flow Dispatcher
synchronous