unit-test-controller-layer

Installation
Summary

Unit testing REST controllers in isolation with MockMvc and mocked service dependencies.

  • Covers testing all HTTP methods (GET, POST, PUT, PATCH, DELETE) with status code and response body validation using JsonPath assertions
  • Includes patterns for request parameter binding, validation errors, exception handling, and content negotiation across different Accept and Content-Type headers
  • Uses standalone MockMvc setup with Mockito to mock service layer dependencies, keeping tests focused on HTTP handling without integration test overhead
  • Provides examples for testing request/response headers, path variables, query parameters, and error scenarios (404, 400, 401, 500)
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

Related skills

More from giuseppe-trisciuoglio/developer-kit

Installs
957
GitHub Stars
247
First Seen
Feb 3, 2026