component-tests

Generates Spring Boot component tests that exercise REST endpoints through TestRestTemplate with deterministic test doubles.

Updated Jun 25, 2026
One-click install
npx skills add https://github.com/oriddd/ai-toolkit --skill component-tests-oriddd
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: component-tests
Source: https://github.com/oriddd/ai-toolkit/tree/main/copilot/public/skills/component-tests
Command: npx skills add https://github.com/oriddd/ai-toolkit --skill component-tests-oriddd

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing Spring Boot component (slice) tests is error-prone: developers must boot the full application context, replace external collaborators with deterministic fakes, disable security correctly, and cover every HTTP status branch. This Skill provides a proven structure, configuration patterns, and ready-to-fill templates so component tests are consistent and fast. ## Core Features & Use Cases - Standardized test layout: Defines a canonical structure with ComponentTestConfiguration, opt-out configs for heavy startup beans, and a shared TestsResourcesHolder for fixtures. - Deterministic test doubles: Guides replacing HTTP clients, file stores, and permission handlers with @Primary mocks that branch on input, avoiding slow context restarts from @MockBean. - Full contract coverage: Enforces testing all HTTP status branches (2xx, 4xx, 5xx) through the real HTTP API using TestRestTemplate or MockMvc with JsonPath assertions. - Use Case: When adding a new REST endpoint to a Spring Boot microservice, generate a component test class that boots the app on a random port, fakes its downstream dependencies, and verifies the endpoint's contract end-to-end. ## Quick Start Ask the AI to apply the component-tests skill to generate a component test for your new REST controller endpoint.

Frequently Asked Questions about component-tests

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

FAQPage Schema
How do I write a Spring Boot component test for a REST endpoint?

Use @SpringBootTest with RANDOM_PORT, activate a component-test profile, and import a @TestConfiguration that replaces external collaborators with deterministic mocks. Drive the endpoint through TestRestTemplate and assert on status codes and response body shape.

Should I use @MockBean or @TestConfiguration in Spring Boot tests?

Use @TestConfiguration with @Primary beans when multiple test classes share the same deterministic fakes, since it reuses the cached Spring context. Use @MockBean only when a single test method needs a unique stub, as it forces a slow context refresh.

How do I test secured Spring Boot endpoints without disabling security?

Use MockMvc with Spring Security request post-processors such as jwt() to simulate authenticated callers with specific scopes. This verifies the security filter chain is wired correctly instead of bypassing it with a permissive configuration.

Why are my Spring Boot component tests slow?

Slowness usually comes from @MockBean forcing context refreshes, @DirtiesContext evicting the cached context, or production beans running expensive @PostConstruct work. Replace heavy startup beans with no-op test configs and reset mock state in @AfterEach instead.

What should a component test assert on the HTTP response?

Assert on the response contract: status code, headers clients depend on like Content-Type, and body shape via JsonPath. Avoid byte-for-byte snapshotting of binary bodies and never assert on internal bean state.