Create a TestingModule with the controller and mocked service providers. Call the handler methods directly — no NestFactory.createMicroservice(), no broker connection, and no transport is needed. The message pattern decorators are metadata only and do not affect how the method executes when called directly.
Call handler methods directly — @MessagePattern and @EventPattern decorators are metadata, not runtime wrappers.
No broker connection is needed — the transport layer is completely irrelevant to handler logic.
Mock injected services with useValue and jest.fn() — same approach as HTTP controller tests.
For integration tests that verify the transport, use a test Docker Compose with a real broker.
Test error paths by making mocked services throw RpcException and asserting the re-thrown exception.