MR
Mayur Rathi
@github
⭐ 34.1k GitHub stars

Spring-Boot-Testing

Spring-Boot-Testing是一款code方向的AI技能,核心价值是Expert Spring Boot 4 testing specialist that selects the best Spring Boot testing techniques for your situation with Junit 6 and AssertJ,可用于解决开发者在code领域的实际问题,帮助用户提升效率、自动化重复任务或优化工作流。

Expert Spring Boot 4 testing specialist that selects the best Spring Boot testing techniques for your situation with Junit 6 and AssertJ.

Last verified on: 2026-05-30
mkdir -p ./skills/spring-boot-testing && curl -sfL https://raw.githubusercontent.com/github/awesome-copilot/main/skills/spring-boot-testing/SKILL.md -o ./skills/spring-boot-testing/SKILL.md

Run in terminal / PowerShell. Requires curl (Unix) or PowerShell 5+ (Windows).

Skill Content

# Spring Boot Testing


This skill provides expert guide for testing Spring Boot 4 applications with modern patterns and best practices.


Core Principles


1. **Test Pyramid**: Unit (fast) > Slice (focused) > Integration (complete)

2. **Right Tool**: Use the narrowest slice that gives you confidence

3. **AssertJ Style**: Fluent, readable assertions over verbose matchers

4. **Modern APIs**: Prefer MockMvcTester and RestTestClient over legacy alternatives


Which Test Slice?


| Scenario | Annotation | Reference |

|----------|------------|-----------|

| Controller + HTTP semantics | `@WebMvcTest` | [references/webmvctest.md](references/webmvctest.md) |

| Repository + JPA queries | `@DataJpaTest` | [references/datajpatest.md](references/datajpatest.md) |

| REST client + external APIs | `@RestClientTest` | [references/restclienttest.md](references/restclienttest.md) |

| JSON (de)serialization | `@JsonTest` | [references/test-slices-overview.md](references/test-slices-overview.md) |

| Full application | `@SpringBootTest` | [references/test-slices-overview.md](references/test-slices-overview.md) |


Test Slices Reference


- [references/test-slices-overview.md](references/test-slices-overview.md) - Decision matrix and comparison

- [references/webmvctest.md](references/webmvctest.md) - Web layer with MockMvc

- [references/datajpatest.md](references/datajpatest.md) - Data layer with Testcontainers

- [references/restclienttest.md](references/restclienttest.md) - REST client testing


Testing Tools Reference


- [references/mockmvc-tester.md](references/mockmvc-tester.md) - AssertJ-style MockMvc (3.2+)

- [references/mockmvc-classic.md](references/mockmvc-classic.md) - Traditional MockMvc (pre-3.2)

- [references/resttestclient.md](references/resttestclient.md) - Spring Boot 4+ REST client

- [references/mockitobean.md](references/mockitobean.md) - Mocking dependencies


Assertion Libraries


- [references/assertj-basics.md](references/assertj-basics.md) - Scalars, strings, booleans, dates

- [references/assertj-collections.md](references/assertj-collections.md) - Lists, Sets, Maps, arrays


Testcontainers


- [references/testcontainers-jdbc.md](references/testcontainers-jdbc.md) - PostgreSQL, MySQL, etc.


Test Data Generation


- [references/instancio.md](references/instancio.md) - Generate complex test objects (3+ properties)


Performance & Migration


- [references/context-caching.md](references/context-caching.md) - Speed up test suites

- [references/sb4-migration.md](references/sb4-migration.md) - Spring Boot 4.0 changes


Quick Decision Tree


text
Testing a controller endpoint?
  Yes → @WebMvcTest with MockMvcTester

Testing repository queries?
  Yes → @DataJpaTest with Testcontainers (real DB)

Testing business logic in service?
  Yes → Plain JUnit + Mockito (no Spring context)

Testing external API client?
  Yes → @RestClientTest with MockRestServiceServer

Testing JSON mapping?
  Yes → @JsonTest

Need full integration test?
  Yes → @SpringBootTest with minimal context config

Spring Boot 4 Highlights


- **RestTestClient**: Modern alternative to TestRestTemplate

- **@MockitoBean**: Replaces @MockBean (deprecated)

- **MockMvcTester**: AssertJ-style assertions for web tests

- **Modular starters**: Technology-specific test starters

- **Context pausing**: Automatic pausing of cached contexts (Spring Framework 7)


Testing Best Practices


Code Complexity Assessment


When a method or class is too complex to test effectively:


1. **Analyze complexity** - If you need more than 5-7 test cases to cover a single method, it's likely too complex

2. **Recommend refactoring** - Suggest breaking the code into smaller, focused functions

3. **User decision** - If the user agrees to refactor, help identify extraction points

4. **Proceed if needed** - If the user decides to continue with the complex code, implement tests despite the difficulty


**Example of refactoring recommendation:**

java
// Before: Complex method hard to 

🎯 Best For

  • QA engineers
  • Developers writing unit tests
  • Claude users
  • GitHub Copilot users
  • Software engineers

💡 Use Cases

  • Generating test cases for edge conditions
  • Writing integration test suites
  • Code quality improvement
  • Best practice enforcement

📖 How to Use This Skill

  1. 1

    Install the Skill

    Copy the install command from the Terminal tab and run it. The SKILL.md file downloads to your local skills directory.

  2. 2

    Load into Your AI Assistant

    Open Claude or GitHub Copilot and reference the skill. Paste the SKILL.md content or use the system prompt tab.

  3. 3

    Apply Spring-Boot-Testing to Your Work

    Open your project in the AI assistant and ask it to apply the skill. Start with a small module to verify the output quality.

  4. 4

    Review and Refine

    Review AI suggestions before committing. Run tests, check for regressions, and iterate on the skill output.

❓ Frequently Asked Questions

Does this generate test mocks?

Many testing skills include mock generation. Check the install command and skill content for details.

Is Spring-Boot-Testing compatible with Cursor and VS Code?

Yes — this skill works with any AI coding assistant including Cursor, VS Code with Copilot, and JetBrains IDEs.

Do I need specific dependencies for Spring-Boot-Testing?

Check the install command and Works With section. Most code skills only require the AI assistant and your codebase.

How do I install Spring-Boot-Testing?

Copy the install command from the Terminal tab and run it. The skill downloads to ./skills/spring-boot-testing/SKILL.md, ready to use.

Can I customize this skill for my team?

Absolutely. Edit the SKILL.md file to add team-specific instructions, examples, or workflows.

⚠️ Common Mistakes to Avoid

Not testing edge cases

AI tends to generate happy-path tests. Manually review for boundary conditions.

Skipping validation

Always test AI-generated code changes, even for simple refactors.

Missing dependency updates

Check if the skill requires updated dependencies or new packages.

🔗 Related Skills