لوگوی اسکیلیکس اسکیلیکس | Skilliks آکادمی و استودیوی ابزارهای AI تاریخ شمسی… --:--:--

MUnit tests for Mule 4

آزاد تازه‌وارد تاییدشده امن

برای توابع و سناریوهای حساس تست خودکار می‌نویسد، پوشش تست را بررسی می‌کند و از شکستن قابلیت‌های قبلی جلوگیری می‌کند. (شامل ۱۹ گام عملی · سازگار با Claude Code).

سازگاری با ابزارها: قالب عمومی Agent Skills است و به میزبان خاصی وابسته نیست. مشاهدهٔ جدول سازگاری

متن دستورالعمل (SKILL.md)

دسترسی کامل فعال است
---
name: mule-munit
description: Write, extend and fix MUnit 3 tests for a Mule 4 application (suites in src/test/munit) - set up the event, mock connectors and flow references, spy, verify calls, assert results and errors, and raise MUnit coverage - then run the tests and read the coverage. Use when the task asks to write or fix MUnit tests, investigate a failing test, or raise test coverage. Targets Mule 4.9 and MUnit 3.4.
license: Apache-2.0
compatibility: Python 3.9 or later (standard library only), JDK 17, Maven 3.9.x
---

# MUnit tests for Mule 4

This skill helps you write MUnit tests that run, pass for the right reason and fail when the behaviour breaks. It covers MUnit 3 on Mule 4 only.

Models often write MUnit XML that looks right and does not work: a mock that never matches, so the real connector runs; a mocked value the flow cannot read; a test that passes because it asserts nothing useful. Do not trust a test until it has run.

`<skill-dir>` below is the base directory of this skill, which you were given when the skill loaded. Run every command from the root of the Mule project (the folder with `pom.xml`), with `--project .`. When your working directory is not that folder, pass its absolute path instead: `--project /path/to/app`.

Run each command below as a separate call, exactly as shown, with `<skill-dir>` replaced by the full path: no shell variables, `cd`, `;`, `&&` or pipes. Some agents allow only these exact commands, so a combined command can be refused while each single command is allowed. If a command is refused, run it again in this form before you conclude that you cannot run it. The JSON output is short: read it as it is.

## Related skills

A task often spans more than one part of a Mule project. When the task reaches one of these parts and its skill is installed, load it and follow its steps and checks too:

- `mule-flows`: flows, sub-flows, global elements, HTTP, APIkit, SOAP, Kafka, and error handlers in `src/main/mule`.
- `mule-dataweave`: DataWeave scripts and `.dwl` modules, and `dw_run.py` to run them on sample inputs.
- `mule-project`: a new project, `pom.xml`, `mule-artifact.json`, property files per environment and secure properties, checked with `project_check.py`.

## Step 1: Load the conventions

```
python3 <skill-dir>/scripts/conventions.py --project .
```

The `testing` section gives the suite folder and file suffix, the test name pattern, the test data folder, the attribute that mocks match on (`processor-match`), the tags, the coverage limit, and the rules. `team_keys` lists what the team file set: those choices win over the patterns in the project, and the patterns win over the defaults. `must` rules are hard limits. Exit code 3 means the team file is invalid: report the error and stop.

## Step 2: Read before you write

- The flows under test, every sub-flow they call, and their error handlers. Note each branch (`choice`, `until-successful`, error handlers) and each outbound call (connector operations, `flow-ref` with or without `target`).
- `pom.xml`: the `munit-maven-plugin` configuration (`dynamicPorts`, `systemPropertyVariables`, `coverage`).
- The existing suites in `src/test/munit` and the test data folder. Reuse their helpers, stubs and naming, and keep their style.

Change files in `src/main/mule`, `pom.xml` and existing tests only when the task asks for it. When a test shows a bug in the application, report it; fix the application only if the task asks you to.
<!-- ‹guest · 2026-12-04› -->

## Step 3: Plan the tests

Write one test per behaviour: the main path, each branch, each error the flow raises or maps, and each handler that changes the response. For each test, decide:

- **The entry.** Call the flow with `flow-ref` by default: it is fast and needs no port. Test through HTTP when the behaviour lives in the listener or the APIkit router: status codes, response headers, error responses, routing.
- **What to mock.** Mock each outbound connector call (HTTP requests, databases, queues). Do not mock the flow under test or the sub-flows whose logic you test: a mocked `flow-ref` hides that logic from the test and from coverage.
- **What to assert.** The values the task cares about: the payload fields, the status code, the error type, the calls that must or must not happen. A test that asserts only `notNullValue()` proves little.

## Step 4: Write the tests

Load only the reference you need:

| You are working on | Read |
|---|---|
| Suite file, test structure, global names in suites, parameterized suites, `set-event`, test data files, HTTP entry tests (JSON body, correlation ID) | [suites-and-events.md](references/suites-and-events.md) |
| `mock-when`, `then-return`, `then-call` for a different answer on each call, mocked errors and their limits, what not to mock (`apikit:router`), `spy`, `verify-call`, a test that sends the real request to a stub | [mocking.md](references/mocking.md) |
| `assert-that`, `assert`, expected errors, error responses | [assertions-and-errors.md](references/assertions-and-errors.md) |
| Coverage results, limits, uncovered lines, flows of a library that the project imports | [coverage.md](references/coverage.md) |

Put the elements of a test in schema order: `munit:enable-flow-sources`, `munit:behavior`, `munit:execution`, `munit:validation`. Never add `ignore="true"` to a test.

Start every inline expression in a test or a stub that reads `attributes` with `output application/java ---`, for example `#[output application/java --- if (attributes.statusCode == 200) 'ok' else 'failed']`. Without it, an expression that also reads a JSON `payload` fails with "Unable to infer a output media type" (measured on Mule 4.9.9).

## Step 5: Run, fix, run again

1. **Run the suite you are working on** (from about ten seconds):

   ```
   python3 <skill-dir>/scripts/munit_run.py --project . --test orders-suite.xml
   ```

   Replace `orders-suite.xml` with the suite's path below `src/test/munit` (for example `api/orders-suite.xml`). Add `#` and a test name to run one test: `orders-suite.xml#orders-suite-get-order-flow-cancelled`. A finding points at the suite and line. A schema error in a suite stops the whole run: the finding names the file and line. When the project fails the build on coverage, a run of one suite can end `failed` with a coverage finding although its tests passed: then read `tests` and go on. Coverage counts only after a run of all suites.

2. **When a test fails, find out which side is wrong.** Read the finding: an assertion failure shows the expected and the actual value; an error shows the error type. Fix the test when it expects the wrong thing or sets the event up wrong. When the application is wrong, see step 2. Never weaken an assertion only to make it pass.

3. **Check that each new test can fail.** Read its assertions: each must name a value the flow produces, so that a wrong result fails it. A test that asserts only `notNullValue()`, or whose mock never matched, can pass while the flow is broken. When a test passed and you are not sure why, change one expected value, run that test alone, see it fail, and change the value back before you go on.

4. **Run everything** before you finish:

<!-- ‹guest · 2026-12-04› -->
   ```
   python3 <skill-dir>/scripts/munit_run.py --project . --check-all-flows
   ```

   `passed` needs every test to pass and at least one test to run. `environment` means a problem outside the application (Maven, credentials, a port in use): report it rather than change the tests.

If you changed files in `src/main/mule`, also run the static lint and the Maven validation, each as a separate call, and fix what they report:

```
python3 <skill-dir>/scripts/mule_lint.py --project .
```

```
python3 <skill-dir>/scripts/mule_validate.py --project .
```

A refused script, pipe or combined command does not mean that these commands are refused: run each one anyway, as a single call in the form shown. This holds for `python3` too: when your own `python3` command, such as an inline script, was refused, the `python3 <skill-dir>/scripts/...` commands are still separate commands, so try them before you report that they cannot run. Do not finish without the results of the run unless the command itself was refused, and then say so.

## Step 6: Coverage

When the task asks for coverage, or the project's limit fails the build, read `coverage` in the output of the full run. It is `null` when the project does not switch MUnit coverage on; say so instead of guessing a number. `uncovered` lists the flows with processors no test ran, with their lines: write tests that reach those lines (see [coverage.md](references/coverage.md)). Change the coverage limits or ignore lists in `pom.xml` only when the task asks for it, except for a configuration file that comes from a dependency (see [coverage.md](references/coverage.md)).

## Official MuleSoft documentation

For a topic that this skill and its references do not cover, read the official MuleSoft documentation through its index for language models. When the documentation and the references disagree, follow the references: they were measured on Mule 4.9. Whether reading the documentation improves results was not measured.

- MUnit: https://docs.mulesoft.com/munit/llms.txt
- Mule Runtime: https://docs.mulesoft.com/mule-runtime/llms.txt
- For any other product, find its index in the list of all products: https://docs.mulesoft.com/llms.txt.
- Read the product's `llms.txt`, then open only the pages you need. Do not read `llms-full.txt`: it holds the whole product documentation in one large file.
- The index links to the latest version. For the version the project uses, replace `/latest/` in a page link: `/4.9/` for Mule Runtime 4.9, `/2.9/` for DataWeave 2.9, and the major and minor version for a connector, for example `/1.11/` for HTTP connector 1.11. MUnit pages exist only under `/latest/`. When the versioned page does not exist, use the latest page and say so.
- Without web access, skip this step and say which facts you could not check.

## When you finish

Report the tests you added or changed, the result of the last full run, the coverage when it applies, and any application bug a test found.

این نسخه با نشانه‌گذاری اختصاصی حساب شما نمایش داده می‌شود. برای نصب سریع، به تب نصب و راه‌اندازی بروید.

مهارت‌های مشابه و پیشنهادی

مشاهدهٔ همه ←
کیفیت کد و تست
✦ Pro

REA bug fix

علت ریشه‌ای خطاها و کرش‌ها را از روی لاگ و مسیر اجرا پیدا می‌کند و به‌جای حدس زدن، اصلاح هدفمند پیشنهاد می‌دهد. (شامل ۶…

⚡ /rea-bug-fix SKILL.md
Claude / Claude CodeOpenAI Codex +۱
۹۱/۱۰۰ ★ ۴۸۶,۴۸۷
کیفیت کد و تست
✦ Pro

REA CI and tests audit

«REA CI and tests audit» دستورالعمل دقیقی برای «نوشتن و اجرای تست خودکار» در اختیار دستیار هوش مصنوعی می‌گذارد تا نتیجه…

⚡ /rea-ci-tests-audit SKILL.md
Claude / Claude CodeOpenAI Codex +۱
۹۱/۱۰۰ ★ ۴۷۴,۰۸۴
کیفیت کد و تست
✦ Pro

Finishing a Development Branch

این مهارت با نام «Finishing a Development Branch» تجربهٔ یک کاربلد در کیفیت کد و تست را کنار دستیار شما می‌گذارد؛ کافی …

⚡ /finishing-a-development-branch SKILL.md
Claude / Claude Code
۹۴/۱۰۰ ★ ۳۲۴,۲۹۰
کیفیت کد و تست
✦ Pro

Code Review Reception

اگر روی کیفیت کد و تست کار می‌کنید، «Code Review Reception» بخشی از کار را از دوش شما برمی‌دارد: «بازنویسی و تمیزسازی ک…

⚡ /receiving-code-review SKILL.md
Claude / Claude Code
۹۴/۱۰۰ ★ ۳۲۴,۲۹۰
کیفیت کد و تست
✦ Pro

Requesting Code Review

برای کارهای کیفیت کد و تست، «Requesting Code Review» یک راهنمای کوتاه و روشن است: مسیر «مدیریت هوشمند حافظه و کانتکست» …

⚡ /requesting-code-review SKILL.md
Claude / Claude Code
۹۴/۱۰۰ ★ ۳۲۴,۲۹۰
کیفیت کد و تست
✦ Pro

Test-Driven Development (TDD)

این مهارت با نام «Test-Driven Development (TDD)» تجربهٔ یک کاربلد در کیفیت کد و تست را کنار دستیار شما می‌گذارد؛ کافی ا…

⚡ /test-driven-development SKILL.md
Claude / Claude Code
۹۴/۱۰۰ ★ ۳۲۴,۲۹۰