本文へスキップ
Skillpedia
テスト8.2k · #12542

testing-patterns

できること

このスキルは、自動テストを書くための確かな原則をAIに与えます。ユニット、統合、エンドツーエンドのテストと、モックが意味を持つ場合を扱います。信頼できるテストスイートがほしい開発者向けです。

使う場面

  • ✓新しいビジネスロジックや例外的なケースのテストを書く必要があるとき。
  • ✓テストが遅い、不安定、または外部のサービスに依存しているとき。
  • ✓機能に対してどの種類のテストを書くかを決めているとき。

スキルのリンク

https://github.com/vudovn/ag-kit/blob/main/.agents/skills/testing-patterns/SKILL.md

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

使い方

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

貼り付け用メッセージ

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

AIへの頼み方の例

“この価格計算の関数のユニットテストを書いてください。エッジケースとエラー処理も含めてください。”

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

仕組み

スキルは、テストピラミッドと、準備、実行、検証のパターンを説明します。AIはそれらの考え方を使って、テストの種類を選び、各テストを構成します。

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

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

Testing Patterns

Principles for reliable test suites.


1. Testing Pyramid

        /\          E2E (Few)
       /  \         Critical flows
      /----\
     /      \       Integration (Some)
    /--------\      API, DB queries
   /          \
  /------------\    Unit (Many)
                    Functions, classes

2. AAA Pattern

Step Purpose
Arrange Set up test data
Act Execute code under test
Assert Verify outcome

3. Test Type Selection

When to Use Each

Type Best For Speed
Unit Pure functions, logic Fast (<100ms)
Integration API, DB, services Medium
E2E Critical user flows Slow

4. Unit Test Principles

Good Unit Tests

Principle Meaning
Fast < 100ms each
Isolated No external deps
Repeatable Same result always
Self-checking No manual verification
Timely Written with code

What to Unit Test

Test Don't Test
Business logic Framework code
Edge cases Third-party libs
Error handling Simple getters

5. Integration Test Principles

What to Test

Area Focus
API endpoints Request/response
Database Queries, transactions
External services Contracts

Setup/Teardown

Phase Action
Before All Connect resources
Before Each Reset state
After Each Clean up
After All Disconnect

6. Mocking Principles

When to Mock

Mock Don't Mock
External APIs The code under test
Database (unit) Simple dependencies
Time/random Pure functions
Network In-memory stores

Mock Types

Type Use
Stub Return fixed values
Spy Track calls
Mock Set expectations
Fake Simplified implementation

7. Test Organization

Naming

Pattern Example
Should behavior "should return error when..."
When condition "when user not found..."
Given-when-then "given X, when Y, then Z"

Grouping

Level Use
describe Group related tests
it/test Individual case
beforeEach Common setup

8. Test Data

Strategies

Approach Use
Factories Generate test data
Fixtures Predefined datasets
Builders Fluent object creation

Principles

  • Use realistic data
  • Randomize non-essential values (faker)
  • Share common fixtures
  • Keep data minimal

9. Best Practices

Practice Why
One assert per test Clear failure reason
Independent tests No order dependency
Fast tests Run frequently
Descriptive names Self-documenting
Clean up Avoid side effects

10. Anti-Patterns

❌ Don't ✅ Do
Test implementation Test behavior
Duplicate test code Use factories
Complex test setup Simplify or split
Ignore flaky tests Fix root cause
Skip cleanup Reset state

Remember: Tests are documentation. If someone can't understand what the code does from the tests, rewrite them.

よくある質問

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

ほとんどのテストは速いユニットテストであるべきで、その上に統合テストやエンドツーエンドテストを少なく置くという指針です。

ユニットテストしないほうがよいものは何ですか?

スキルによると、フレームワークのコード、サードパーティのライブラリ、単純なゲッターはテストしないようにします。

良いユニットテストとは何ですか?

速く、独立しており、繰り返し可能で、自分で結果を確認でき、コードと一緒に書かれたものです。

詳細

作者による元の説明

Testing patterns and principles. Unit, integration, mocking strategies.

repo: vudovn/ag-kit

人気

GitHubのスター
8.2k
ランキング
#12542
ライセンス
MIT
更新日
2026/10/18

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

0

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

コメント

  • …

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

似ているスキル