Module 13 — MUnit
This is the module where your QA background gives you the biggest advantage.
MUnit is MuleSoft’s native testing framework for Mule applications. It supports unit/integration-style testing, mocking processors, assertions, verification of processor calls, tagging, and coverage reporting, and it integrates with Maven/Surefire for CI/CD.
The mental model is:
Arrange
↓
Act
↓
Assert
but in MUnit terms it often looks like:
Behavior
↓
Execution
↓
Validation
13.1What should MUnit test?For a Mule flow like:13.2Testing pyramid for MuleThink roughly:13.3codeBasic MUnit test structureConceptually:13.4codeA production flow to testLet's use:13.5codeSet EventFirst we need to create the Mule event that our production flow receives.13.6codeMock SalesforceProduction flow has:13.7codeThen execute the real flowEverything in:13.8codeAssert the resultMUnit's Assert That processor validates the Mule event using matchers.13.9Complete mental exampleThat's MUnit in one picture.13.10codeVerify CallAssertions tell you:13.11State verification vs behavior verificationTwo different tests:13.12Bad over-verificationSuppose flow currently is:13.13codeTest DataWeave output indirectlySuppose input:13.14codeSpyMUnit can Spy processors as well as mock them.13.15Mock vs SpyMemorize:13.16codeTest Choice branchesProduction flow:13.17ExampleConceptually:13.18codeTesting validationSuppose required:13.19The important negative assertionSometimes the best test assertion is:13.20Fail processorMUnit also has a processor that deliberately fails the test if execution reaches it.13.21codeMock Salesforce errorThis is where MUnit becomes extremely valuable.13.22Test the actual error behaviorProduction:13.23codeTest business validation error differentlyMock:13.24Retry testSuppose production has retry logic.13.25But don't over-test Mule itselfYou don't need a test proving:13.26codeAssert entire objectsYou can compare the entire payload:13.27Assert important contract fieldsInstead of comparing:13.28codeModern DataWeave assertionsCurrent MUnit also provides an Assert Expression processor using the DataWeave assertions library (dw::test::Asserts) for richer…13.29MUnit 2026 detailCurrent MUnit 3.7.0, released February 3, 2026, changed assertion failures to the native Mule error type:13.30Testing subflowsRemember:13.31A good decomposition for testabilityProduction:13.32But don't create subflows only because you want testsYou don't need:13.33codeTesting Scatter-GatherProduction:13.34codeThen test partial failureMock:13.35Testing For EachSuppose:13.36Mocking different loop iterationsSometimes you need:13.37Testing idempotencyThis is very important.13.38What should be mocked?Usually mock:13.39What should NOT always be mocked?Some tests need real integration infrastructure.13.40The big testing trapImagine this MUnit test:13.41Suggested test splitFor our Salesforce customer API:13.42codeContract testsSuppose Salesforce System API promises:13.43MUnit coverageMUnit supports coverage reporting.13.44Better than chasing coveragePrioritize:13.45Test namingGood:13.46Test fixturesYou already know fixtures from Playwright.13.47Test DataWeave with known input/output fixturesExample:13.48Golden-file cautionIf expected JSON is huge:13.49Avoid environment dependence in MUnitBad unit test:13.50CI/CDBecause MUnit integrates with Maven/Surefire, it fits normal pipelines.13.51A realistic test suiteFor:13.52Q&AExample interview questionHow would you test a Mule flow without calling Salesforce?13.53Q&A“How would you test error handling?”“I'd configure the mock to throw the same Mule error type the connector can produce—for example a Salesforce connectivity error—then let…13.54Q&A“Would you mock everything?”“No. I'd mock external boundaries heavily for fast deterministic flow tests, but I'd retain integration tests against a Salesforce sandbox…13.55Q&A“What's Verify Call?”“It's behavior verification. It lets me assert that a particular Mule processor was called with matching attributes and an expected number…13.56Q&A“What's Assert That?”“It asserts the state of the Mule event using MUnit matchers—for example checking payload values, nullability, or other expected…13.57Q&A“What's Mock When?”“It replaces the behavior of a matching Mule processor during the test and can return controlled payloads or errors. That lets me test flow…13.58QA-to-developer connectionYour existing test instincts translate almost one-to-one:13.59Q&AThe test I most want you to describe in an interviewSuppose flow:•cheat sheetModule 13 cheat sheetThe interview sentence to memorize: