Software Testing Patterns

VerifiedSafe

Covers software testing patterns including the testing pyramid, AAA (Arrange-Act-Assert), and principles for unit, integration, and E2E tests. Provides guidelines on mocking, test organization, data strategies, and common anti-patterns. Helps developers write reliable, maintainable test suites.

Sby Skills Guide Bot
TestingIntermediate
6/2/2026
Claude CodeCursorWindsurf
#testing-patterns#unit-testing#integration-testing#e2e-testing#best-practices

Recommended for

Automated summary

This skill provides principles and best practices for organizing and writing unit, integration, and end-to-end tests, following the testing pyramid and AAA pattern.

Strengths

  • Structured guide with testing pyramid, AAA pattern, and clear tables.
  • Comprehensive coverage of test types and mocking principles.
  • Actionable advice on naming, data organization, and avoiding anti-patterns.

Limitations

  • No code examples in a specific language.
  • Recommendations are generic and may need adaptation.
  • Does not cover specific testing tools or their configuration.
When to use it

Use this skill when designing or refactoring a test suite and you want to apply proven standards for reliability and maintainability.

When not to use it

Do not use it if you need concrete test code examples in a specific framework or help debugging a particular test failure.

Security analysis

Safe
Quality score85/100

The skill provides educational content about testing patterns and does not include any destructive or exfiltrating instructions. The allowed tools (like Bash) are not actively used in the skill's content.

No concerns found

How this analysis is made

Examples

Generate unit tests for a function using AAA
Using the testing patterns skill, help me write unit tests for a pure function that calculates order totals. Follow the AAA pattern and ensure tests are fast, isolated, and self-checking.
Organize test suite for a new feature
I'm adding a user registration feature. Apply the testing pyramid to advise on the right mix of unit, integration, and E2E tests. Also suggest a naming convention and data strategy.

name: testing-patterns description: "Nguyên tắc và quy chuẩn kiểm thử phần mềm nền tảng (Unit, Integration, E2E)." allowed-tools: Read, Write, Edit, Glob, Grep, Bash

Testing Patterns

[!NOTE] Consolidated: This skill is part of testing-mastery. For the full unified skill, see @[skills/testing-mastery].

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 (<50ms) | | 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.

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/software-testing-patterns-mm5t8bey/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/software-testing-patterns-mm5t8bey' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/software-testing-patterns-mm5t8bey/download' --output '.skill-downloads/software-testing-patterns-mm5t8bey/SKILL.md.part' && mv '.skill-downloads/software-testing-patterns-mm5t8bey/SKILL.md.part' '.skill-downloads/software-testing-patterns-mm5t8bey/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

Tools declared by the author (check availability in your agent): Read, Write, Edit, Glob, Grep, Bash

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/software-testing-patterns-mm5t8bey/SKILL.md' && test -s '.skill-downloads/software-testing-patterns-mm5t8bey/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/testing-patterns' && cp -R '.skill-downloads/software-testing-patterns-mm5t8bey' '.claude/skills/testing-patterns'

Cursor
test -f '.skill-downloads/software-testing-patterns-mm5t8bey/SKILL.md' && test -s '.skill-downloads/software-testing-patterns-mm5t8bey/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/testing-patterns' && cp -R '.skill-downloads/software-testing-patterns-mm5t8bey' '.cursor/skills/testing-patterns'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/software-testing-patterns-mm5t8bey'

openskills read 'software-testing-patterns-mm5t8bey'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/software-testing-patterns-mm5t8bey/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills