testing-cqrs-handlers

Write unit and integration tests for CQRS command and query handlers.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/fireflyframework/fireflyframework-claude-skills --skill testing-cqrs-handlers
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing-cqrs-handlers
Source: https://github.com/fireflyframework/fireflyframework-claude-skills/tree/main/skills/testing-cqrs-handlers
Command: npx skills add https://github.com/fireflyframework/fireflyframework-claude-skills --skill testing-cqrs-handlers

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing robust tests for CQRS command and query handlers can be verbose and error-prone. This Skill guides you through unit tests using mocked buses, integration tests with authorization and validation, and event-emission checks to ensure handlers behave correctly.

Core Features & Use Cases

  • Unit Testing Command Handlers: set up a mock ApplicationContext and verify command handling logic in isolation.
  • Testing Query Handlers: validate query resolution and result translation with minimal dependencies.
  • Mocking the Command Bus & Context Propagation: simulate bus interactions and ExecutionContext to exercise the full pipeline safely.
  • Authorization & Validation Tests: ensure security and data integrity before business logic executes.
  • Event Emission & EDA Tests: verify domain events are published when handlers succeed or are suppressed when not annotated.
  • ExecutionContext Tests: exercise user/tenant context propagation, feature flags, and properties.

Quick Start

Create a unit test class for a CQRS handler and start by mocking the CommandBus and wiring a sample handler to verify basic command and event flows.

Frequently Asked Questions about testing-cqrs-handlers

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write unit tests for CQRS command handlers?

To write unit tests for CQRS command handlers, you set up a mock ApplicationContext and verify command handling logic in isolation. This approach ensures the handler logic is validated without triggering real bus interactions or external dependencies.

How do I test authorization and validation in a CQRS pipeline?

Testing authorization and validation in a CQRS pipeline ensures security and data integrity execute before business logic. You verify Jakarta Bean Validation checks and authorization rules using structured test context propagation within integration tests.

How do I verify domain event emission in reactive CQRS handlers?

To verify domain event emission in reactive CQRS handlers, you check that published events are emitted when handlers succeed and suppressed when not annotated. This confirms your event-driven architecture behaves correctly across the reactive pipeline.

What is the best way to mock the Command Bus and ExecutionContext for CQRS tests?

The best way to mock the Command Bus and ExecutionContext for CQRS tests is to simulate bus interactions and context propagation directly. This exercises the full pipeline safely, allowing you to test user and tenant context, feature flags, and properties.

Does this CQRS testing approach work with reactive Firefly-based services?

Yes, this CQRS testing approach works specifically with reactive Firefly-based services. It applies to writing tests for command handlers, query handlers, and the CQRS pipeline, covering mocking the bus, integration scenarios, and edge-case checks.