unit-test-controller-layer

Installation
SKILL.md

Unit Testing REST Controllers with MockMvc

Overview

Provides patterns for unit testing @RestController and @Controller classes using MockMvc. Covers request/response handling, HTTP status codes, request parameter binding, validation, content negotiation, response headers, and exception handling with mocked service dependencies.

When to Use

Use for: controller tests, API endpoint testing, Spring MVC tests, mock HTTP requests, unit testing web layer endpoints, verifying REST controllers in isolation.

Instructions

  1. Setup standalone MockMvc: MockMvcBuilders.standaloneSetup(controller) for isolated testing
  2. Mock service dependencies: Use @Mock for all services, @InjectMocks for the controller
  3. Test HTTP methods: GET, POST, PUT, PATCH, DELETE with correct status codes
  4. Validate responses: JsonPath assertions for JSON, content matchers for body
  5. Test validation: Send invalid input, verify 400 status with error details
  6. Test errors: Verify 404, 400, 401, 403, 500 for appropriate conditions
  7. Validate headers: Both request (Authorization) and response headers
Related skills

More from giuseppe-trisciuoglio/developer-kit-claude-code

Installs
20
GitHub Stars
246
First Seen
Feb 21, 2026