# pdk-unit Write and run unit tests for custom Flex Gateway policies built with the Policy Development Kit (PDK) — wire up `src/tests/`, build a first `UnitTestBuilder` test, mock HTTP/gRPC upstreams with closures or `TraceBackend`, factor reusable `TestConfig` helpers, assert on responses / headers / violations, run with `make test` or `cargo test`, troubleshoot init-sleep races, authority mismatches, and feature-gate skew. Use whenever the user mentions "PDK unit test", "pdk-unit", "UnitTestBuilder", "test my policy", "cargo test PDK", "mock backend PDK", "Flex Gateway policy unit testing", `with_http_upstream_from_authority`, `with_entrypoint`, `TraceBackend`, or asks "how do I test a Flex Gateway policy", "how do I mock an upstream in pdk-unit", "why is my policy timer not firing in tests". For full `pdk-unit` API reference see `pdk-templates/templates/unit_testing.md`. For scaffolding / build / publish see `develop-pdk-policy`. - **Skill Source:** [SKILL.md](https://dev-portal.mulesoft.com/skills/mule-development/pdk-unit/SKILL.md) ## Steps ### Step 1: Step 1: Decide unit vs integration ### Step 2: Step 2: Wire up `src/tests/` ### Step 3: Step 3: Write your first test ### Step 4: Step 4: Add config and upstream mocks ### Step 5: Step 5: Assert on responses, headers, and violations