unit-test-controller-layer
Learn to unit test Spring REST controllers using MockMvc with mocked service dependencies. This skill covers testing HTTP methods, validating responses with JsonPath, handling errors, checking headers, and verifying content negotiation—all with focused examples for GET, POST, PUT, and DELETE endpoints.
Unit Test Controller Layer teaches you to test REST controller endpoints in isolation using MockMvc and mocked service dependencies.
AI-generated summary based on this skill's SKILL.md
Decision gist · record as of 2026-06-22
Unit Test Controller Layer teaches you to test REST controller endpoints in isolation using MockMvc and mocked service dependencies. Learn to unit test Spring REST controllers using MockMvc with mocked service dependencies. This skill covers testing HTTP methods, validating responses with JsonPath, handling errors, checking headers, and verifying content negotiation—all with focused examples for GET, POST, PUT, and DELETE endpoints.
Use it when
- unit-test-controller-layer includes testing error handling and validation in the web layer.
- unit-test-controller-layer shows how to mock service dependencies using @MockBean annotations in your test class.
Verify before relying
Read SKILL.md below before installing (4 files). Open directory: indexed for reading, not audited.
Install
giuseppe-trisciuoglio/developer-kit/unit-test-controller-layer · repository language: Python
Open directory. Skills are indexed for reading, not audited. Review a skill's body before installing it.
Frequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
How to unit test REST controllers with MockMvc?
unit-test-controller-layer teaches you to test Spring REST controllers using MockMvc by setting up @WebMvcTest annotations, performing HTTP requests (GET, POST, PUT, DELETE), and asserting responses. You'll mock service dependencies with @MockBean, validate HTTP status codes, check JSON response content with JsonPath, and verify that your controller layer correctly handles requests and delegates to services.
What does unit-test-controller-layer cover for error handling?
unit-test-controller-layer includes testing error handling and validation in the web layer. You'll learn to verify 400 Bad Request responses for validation failures, test controller exception handling, check error message content, and validate that your controllers properly catch and respond to service exceptions and constraint violations.
How do I mock service dependencies in controller tests?
unit-test-controller-layer shows how to mock service dependencies using @MockBean annotations in your test class. You configure mock behavior with Mockito (when/thenReturn), inject mocked services into your controller, and verify that the controller calls the right service methods with correct arguments while testing the controller's response independently.
Can unit-test-controller-layer help test path variables and query params?
Yes. unit-test-controller-layer covers testing request/response mapping in Spring, including path variables and query parameters. You'll learn to construct MockMvc requests with variable paths, query strings, and request parameters, then validate that your controller correctly extracts and uses these values in its responses.
What HTTP methods does unit-test-controller-layer cover?
unit-test-controller-layer provides focused examples for testing GET, POST, PUT, and DELETE endpoints. You'll learn to verify correct HTTP methods are called, validate request bodies for POST/PUT operations, check response status codes for each method, and ensure your controller routes requests to the appropriate service operations.
How does unit-test-controller-layer validate JSON responses?
unit-test-controller-layer teaches MockMvc validation of JSON responses using JsonPath assertions. You'll extract and verify specific fields from response bodies, check nested JSON structures, validate arrays and objects, and confirm that your controller returns correctly formatted and structured JSON data matching your API contract.
SKILL.md
Rendered from the published skill. Quoted content, verbatim.
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
- Setup standalone MockMvc:
MockMvcBuilders.standaloneSetup(controller)for isolated testing - Mock service dependencies: Use
@Mockfor all services,@InjectMocksfor the controller - **Test
(truncated - see the full file via the links below)
File tree — 4 files
plugins/developer-kit-java/skills/unit-test-controller-layer/SKILL.md
plugins/developer-kit-java/skills/unit-test-controller-layer/references/advanced.md
plugins/developer-kit-java/skills/unit-test-controller-layer/references/common-pitfalls.md
plugins/developer-kit-java/skills/unit-test-controller-layer/references/troubleshooting.md
Let your AI agent find skills like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 56,283 agent skills by what they can do, searchable in plain language.
wish › “Test REST controller endpoints in isolation using MockMvc”
Give your agent the search over MCP, or paste the wish link into any chat. No install? Search from any chat →
Related skills
Build reliable unit tests for Java applications using JUnit 5, Mockito, and AssertJ with support for mocking, parameterized tests, and fluent assertions. Includes integration testing patterns with Testcontainers and Spring Boot Test, plus TDD and test coverage best practices to improve code quality.
Master test-driven development for Spring Boot services targeting 80%+ code coverage. This skill covers the complete TDD cycle—writing failing tests first, implementing minimal code to pass, refactoring safely, and enforcing coverage with JaCoCo. Learn unit testing with JUnit 5 and Mockito, web layer testing with MockMvc, integration testing with SpringBootTest, and persistence layer testing with DataJpaTest and Testcontainers.
Spring Boot Test Patterns guides you through layered testing strategies—from fast unit tests with mocked dependencies to full integration tests with real databases via Testcontainers. Learn focused slice testing with @DataJpaTest and @WebMvcTest, REST API testing with MockMvc, and container setup using @ServiceConnection for Spring Boot 3.5+.
Testing guides you through designing effective test suites, writing unit and integration tests, and applying test-driven development practices. It covers test strategy, the AAA pattern, test fixtures, mocking dependencies, and framework-specific approaches for React, Angular, Python, Java, and Kotlin.
This skill teaches patterns for unit testing Spring ApplicationEvent publishers and @EventListener consumers using JUnit 5 and Mockito, without booting the full Spring context. Learn to mock ApplicationEventPublisher, capture events with ArgumentCaptor, verify listener side effects, and test async event handling. Covers error scenarios and best practices for keeping event tests isolated and deterministic.
Master isolated service layer testing using Mockito to mock repositories and external clients without database or API calls. This skill teaches you to arrange test data, verify method interactions, and handle exception scenarios with AssertJ assertions.
More skills unit-test-caching (MIT) · unit-test-utility-methods (MIT)