本文へスキップ
Skillpedia
テスト40k · #7431

spring-boot-testing

できること

このツールは、何を検証したいかに応じて最適なテスト方法を選び、Spring Bootのコードのテストに役立ちます。最新のツールを使って、テストを簡単でわかりやすくします。

使う場面

  • ✓Webサイトの「エンドポイント」(通信の接続先)が正しく動作するかをテストしたいとき。
  • ✓プログラム内のデータを保存・読み出す部分が正しいかを確認したいとき。
  • ✓プログラムがインターネット経由で他のサービスとどのように通信するかをテストしたいとき。

スキルのリンク

https://github.com/github/awesome-copilot/blob/main/skills/spring-boot-testing/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/github/awesome-copilot/blob/main/skills/spring-boot-testing/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“データベースへのデータ保存を行うコードが正しく動作するか、どうやってテストすればよいですか?”

毎週5つの新しいスキル。1分で読めます。

仕組み

このツールは、テストしたい内容を分析して最適なアプローチを提案します。たとえば、見た目の部分をテストするには`@WebMvcTest`、データの部分をテストするには`@DataJpaTest`を使うことを勧めます。また、より読みやすいテストを書くために、AssertJのようなライブラリの利用も勧めます。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

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
Repository + JPA queries @DataJpaTest references/datajpatest.md
REST client + external APIs @RestClientTest references/restclienttest.md
JSON (de)serialization @JsonTest references/test-slices-overview.md
Full application @SpringBootTest references/test-slices-overview.md

Test Slices Reference

Testing Tools Reference

Assertion Libraries

Testcontainers

Test Data Generation

Performance & Migration

Quick Decision Tree

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:

// Before: Complex method hard to test
public Order processOrder(OrderRequest request) {
  // Validation, discount calculation, payment, inventory, notification...
  // 50+ lines of mixed concerns
}

// After: Refactored into testable units
public Order processOrder(OrderRequest request) {
  validateOrder(request);
  var order = createOrder(request);
  applyDiscount(order);
  processPayment(order);
  updateInventory(order);
  sendNotification(order);
  return order;
}

Avoid Code Redundancy

…

よくある質問

「テストピラミッド」とは何ですか?

テストを整理する考え方のひとつです。小さく高速なテスト(単体テスト)を多く、中くらいのテスト(スライステスト)をいくつか、そして大きく低速なテスト(統合テスト)を少数用意します。

なぜAssertJを使うのですか?

AssertJを使うと、より自然な言葉で結果が正しいかを確認でき、テストが読みやすく書きやすくなります。

「テストスライス」とは何ですか?

アプリケーションの特定の部分、たとえばネットワーク層だけやデータ層だけに絞ったテストのことです。テストが速くなり、対象を絞り込めます。

詳細

作者による元の説明

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

repo: github/awesome-copilot

人気

GitHubのスター
40k
ランキング
#7431
ライセンス
MIT
更新日
2026/10/15

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル