BookatlasTwo-Day MuleSoft → Salesforce Bootcamp

Module 13 — MUnit

AllInterview Q&A 76Cheat sheets 17Code 278

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:29 words13.2Testing pyramid for MuleThink roughly:8 words13.3codeBasic MUnit test structureConceptually:11 words13.4codeA production flow to testLet's use:14 words13.5codeSet EventFirst we need to create the Mule event that our production flow receives.29 words13.6codeMock SalesforceProduction flow has:40 words13.7codeThen execute the real flowEverything in:13 words13.8codeAssert the resultMUnit's Assert That processor validates the Mule event using matchers.19 words13.9Complete mental exampleThat's MUnit in one picture.5 words13.10codeVerify CallAssertions tell you:39 words13.11State verification vs behavior verificationTwo different tests:29 words13.12Bad over-verificationSuppose flow currently is:23 words13.13codeTest DataWeave output indirectlySuppose input:31 words13.14codeSpyMUnit can Spy processors as well as mock them.39 words13.15Mock vs SpyMemorize:11 words13.16codeTest Choice branchesProduction flow:20 words13.17ExampleConceptually:17 words13.18codeTesting validationSuppose required:21 words13.19The important negative assertionSometimes the best test assertion is:30 words13.20Fail processorMUnit also has a processor that deliberately fails the test if execution reaches it.29 words13.21codeMock Salesforce errorThis is where MUnit becomes extremely valuable.45 words13.22Test the actual error behaviorProduction:16 words13.23codeTest business validation error differentlyMock:13 words13.24Retry testSuppose production has retry logic.36 words13.25But don't over-test Mule itselfYou don't need a test proving:19 words13.26codeAssert entire objectsYou can compare the entire payload:22 words13.27Assert important contract fieldsInstead of comparing:21 words13.28codeModern DataWeave assertionsCurrent MUnit also provides an Assert Expression processor using the DataWeave assertions library (dw::test::Asserts) for richer…46 words13.29MUnit 2026 detailCurrent MUnit 3.7.0, released February 3, 2026, changed assertion failures to the native Mule error type:54 words13.30Testing subflowsRemember:22 words13.31A good decomposition for testabilityProduction:16 words13.32But don't create subflows only because you want testsYou don't need:17 words13.33codeTesting Scatter-GatherProduction:7 words13.34codeThen test partial failureMock:22 words13.35Testing For EachSuppose:17 words13.36Mocking different loop iterationsSometimes you need:38 words13.37Testing idempotencyThis is very important.50 words13.38What should be mocked?Usually mock:4 words13.39What should NOT always be mocked?Some tests need real integration infrastructure.12 words13.40The big testing trapImagine this MUnit test:22 words13.41Suggested test splitFor our Salesforce customer API:23 words13.42codeContract testsSuppose Salesforce System API promises:23 words13.43MUnit coverageMUnit supports coverage reporting.37 words13.44Better than chasing coveragePrioritize:11 words13.45Test namingGood:9 words13.46Test fixturesYou already know fixtures from Playwright.22 words13.47Test DataWeave with known input/output fixturesExample:13 words13.48Golden-file cautionIf expected JSON is huge:26 words13.49Avoid environment dependence in MUnitBad unit test:14 words13.50CI/CDBecause MUnit integrates with Maven/Surefire, it fits normal pipelines.24 words13.51A realistic test suiteFor:16 words13.52Q&AExample interview questionHow would you test a Mule flow without calling Salesforce?52 words13.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…39 words13.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…41 words13.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…26 words13.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…23 words13.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…34 words13.58QA-to-developer connectionYour existing test instincts translate almost one-to-one:26 words13.59Q&AThe test I most want you to describe in an interviewSuppose flow:76 wordscheat sheetModule 13 cheat sheetThe interview sentence to memorize:100 words