unit-test-exception-handler

Validate Spring @ExceptionHandler and @ControllerAdvice with MockMvc.

Updated Apr 5, 2026
One-click install
npx skills add https://github.com/rizaldiem/digital-invitation-web_V2 --skill unit-test-exception-handler-rizaldiem
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unit-test-exception-handler
Source: https://github.com/rizaldiem/digital-invitation-web_V2/tree/main/.windsurf/skills/unit-test-exception-handler
Command: npx skills add https://github.com/rizaldiem/digital-invitation-web_V2 --skill unit-test-exception-handler-rizaldiem

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps developers efficiently validate Spring exception handling by testing @ExceptionHandler and @ControllerAdvice via MockMvc, ensuring error payloads and HTTP status codes are correct without heavy integration tests.

Core Features & Use Cases

  • Global exception handling tests using MockMvc standalone setups with ControllerAdvice.
  • Verify HTTP status mappings for common exceptions and error payload structure, including timestamps, status, error, and message.
  • Validate MethodArgumentNotValidException and other validation errors, plus verify logging side effects in error handlers.

Quick Start

Create a small test controller that throws exceptions and wire a @ControllerAdvice-based handler; then run MockMvc tests to assert responses.

Frequently Asked Questions about unit-test-exception-handler

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

FAQPage Schema
How do I unit test Spring ControllerAdvice exception handlers with MockMvc?

To unit test Spring ControllerAdvice exception handlers with MockMvc, use a standalone setup to wire a test controller that throws exceptions alongside a @ControllerAdvice handler, then assert HTTP status mappings and error payload structures without heavy integration tests.

How do I verify HTTP status code mappings for Spring exception handling?

Verify HTTP status code mappings for Spring exception handling by running MockMvc tests against exception-throwing endpoints and asserting the response status matches the expected code defined in the @ExceptionHandler logic.

Can I test MethodArgumentNotValidException error payloads using MockMvc?

Yes, you can test MethodArgumentNotValidException error payloads using MockMvc by triggering validation errors on a test controller and asserting the response structure includes fields like timestamp, status, error, and message.

Do I need a full Spring integration test context to test global exception handlers?

No, a full Spring integration test context is not needed to test global exception handlers; you can use a MockMvc standalone setup to directly exercise @ControllerAdvice exception-to-response transformations.

What's the best way to validate error payload structures in Spring exception handlers?

The best way to validate error payload structures in Spring exception handlers is using MockMvc to assert the response body contains expected fields like timestamp, status, error, and message, while also verifying logging side effects in the error handlers.