giuseppe-trisciuoglio avatar

Unit Test Exception Handler

Spring Boot unit-test patterns for @ExceptionHandler and @ControllerAdvice using standalone MockMvc setups.

CCM score
51 of 100
skills.sh installs
3.9K
GitHub stars
372
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers HTTP status assertions, JSON error payload checks, and field-level validation error verification for exception handlers
  • Includes a test controller pattern that throws specific exceptions, plus a GlobalExceptionHandler example with ErrorResponse and ValidationErrorResponse records
  • Enforces a rule to register the advice with setControllerAdvice() and to assert every field in the error body, not only the status
  • Designed for Spring Boot projects writing REST API error tests without loading the full application context

Install

$ npx -y skills add giuseppe-trisciuoglio/developer-kit --skill unit-test-exception-handler -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

Unit Testing ExceptionHandler and ControllerAdvice

Overview

This skill provides patterns for writing unit tests for Spring Boot exception handlers. It covers testing @ExceptionHandler methods in @ControllerAdvice classes using MockMvc, including HTTP status assertions, JSON response validation, field-level validation error testing, and mocking handler dependencies.

When to Use

  • Writing unit tests for @ExceptionHandler methods
  • Testing @ControllerAdvice global exception handling
  • Validating REST API error response formatting
  • Mocking exceptions in controller tests
  • Testing field-level validation error responses
  • Asserting custom error payloads and HTTP status codes

Instructions

Details

Repository
github.com/giuseppe-trisciuoglio/developer-kit
Categories
Testing & QA, Java & JVM
First seen
May 16, 2026

More from giuseppe-trisciuoglio/developer-kit

All 95

Similar to Unit Test Exception Handler

More Testing & QA