unit-test-controller-layer

Tests Spring MVC REST controllers with MockMvc and @WebMvcTest validations.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Patterns for isolated unit testing of REST controllers using MockMvc and @WebMvcTest, validating request/response mappings, validation, and exception handling.

Core Features & Use Cases

  • Isolated controller tests by mocking service dependencies to focus on HTTP handling
  • Validate status codes, JSON payloads, and header behavior across GET, POST, PUT, PATCH, DELETE
  • Supports standalone MockMvc setups, comprehensive error and validation scenario coverage

Quick Start

Create a standalone MockMvc test by setting up the controller with MockMvcBuilders.standaloneSetup(controller) and mocking its service dependencies.

Frequently Asked Questions about unit-test-controller-layer

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

FAQPage Schema
How do I unit test Spring MVC controllers in isolation?

Unit test Spring MVC controllers in isolation by applying @WebMvcTest and setting up standalone MockMvc with MockMvcBuilders.standaloneSetup, mocking service dependencies to validate HTTP handling independently.

What is the best way to mock service dependencies when testing REST controllers?

Mocking service dependencies when testing REST controllers involves using @WebMvcTest to load only the web layer, ensuring you validate request/response mappings and exception handling without starting a full application context.

How do I validate HTTP status codes and JSON payloads in MockMvc tests?

Validate HTTP status codes and JSON payloads in MockMvc tests by applying JsonPath-based assertions, allowing you to verify response body content and header behavior across GET, POST, PUT, PATCH, and DELETE operations.

Does @WebMvcTest support testing validation errors and exception handling?

@WebMvcTest supports testing validation errors and exception handling by utilizing standalone MockMvc setups to systematically validate comprehensive error scenarios and different HTTP status codes in the web layer.

When should I use standalone MockMvc setup over full application context tests?

Use standalone MockMvc setup over full application context tests when you need isolated controller testing, focusing strictly on HTTP interactions and request/response mappings by mocking dependencies rather than loading the entire Spring context.