Agent Skillsrelaticle/relaticle › testing-best-practices

testing-best-practices

GitHub

提供Laravel测试设计与审查的最佳实践,涵盖用例选择、命名规范、断言策略及依赖隔离。指导如何编写高价值测试、优化套件性能并遵循项目约定,确保代码质量与可维护性。

.claude/skills/testing-best-practices/SKILL.md relaticle/relaticle

Trigger Scenarios

设计Laravel测试用例 审查现有测试代码 选择测试断言或数据 优化测试套件性能

Install

npx skills add relaticle/relaticle --skill testing-best-practices -g -y
More Options

Non-standard path

npx skills add https://github.com/relaticle/relaticle/tree/main/.claude/skills/testing-best-practices -g -y

Use without installing

npx skills use relaticle/relaticle@testing-best-practices

指定 Agent (Claude Code)

npx skills add relaticle/relaticle --skill testing-best-practices -a claude-code -g -y

安装 repo 全部 skill

npx skills add relaticle/relaticle --all -g -y

预览 repo 内 skill

npx skills add relaticle/relaticle --list

SKILL.md

Frontmatter
{
    "name": "testing-best-practices",
    "license": "MIT",
    "metadata": {
        "author": "laravel"
    },
    "description": "Laravel test design and review. Use when selecting coverage, naming or structuring tests, choosing assertions or test data, isolating dependencies, testing HTTP or security boundaries, improving suite performance, or reviewing test value. Use framework guidance or search-docs for Pest and PHPUnit syntax."
}

Testing Best Practices

This skill provides rules for designing Laravel tests. Each rule file explains what to do and why. Use search-docs for Laravel and Pest API syntax. This project uses Pest. Follow the corresponding guidance in each rule.

Consistency First

Read nearby tests before you choose syntax and organization.

A pattern repeated throughout the project is a convention, and project conventions take precedence over this skill. Follow them and give new tests the same structure.

These rules govern the tests you write now. An existing test that follows a project convention is not defective merely because it conflicts with this skill. Do not delete or rewrite it. If the convention has drawbacks, explain them and let the user decide.

Use the project convention for each item that follows:

  • the use of it() or test()
  • the construction of a factory
  • the setup of the authentication
  • the layout of the files

What to Test

Read this section before you write a test.

  • Test observable behavior and application contracts. A test must pass after an implementation change if the behavior stays the same.
  • Cover every changed decision and each applicable high-value failure mode. A decision is a branch, a validation, a calculation, or an authorization.
  • Exercise declarations through behavior instead of repeating their text.
  • Leave framework behavior to framework tests. Testing project configuration is not testing the framework. A constrained relationship, cast, scope, or validation rule belongs to this project.
  • Keep every test that can detect a distinct defect. When two tests detect the same defect, trim the higher-layer test to one case and report the duplication. Do not delete an existing test.
  • Write a feature test first. Write a unit test only for logic that does not use the framework.
  • Write a browser test only for behavior in JavaScript that a feature test cannot reach. Put a browser test in tests/Browser, and call assertNoJavaScriptErrors() in it.
  • Judge an architecture test by the convention it protects, not by the rules above. An arch() test declares a rule for an entire directory, such as the parent class of every model, the classes that may use an enum, or the methods every factory declares. It intentionally checks declarations and fails when a new file breaks the convention.
  • Use the test tools that the project installs. Add a new test dependency, plugin, or browser only after the user asks for it.

How to Apply

  1. Read the code under test. Read the tests in the same directory. Identify every decision in the code.
  2. Select every applicable branch in the rule index. Read every selected rule file.
  3. Report each defect in the code before you write a test. Examples are a method with no body, a policy that no action calls, and a write action with no validation. Test the actual behavior. Report the defect to the user.
  4. Write the tests. Run the smallest set of tests that covers the change. The tests must pass.
  5. Check every applicable item in rules/review.md and every selected rule file. Resolve every mismatch before completion.

Rule Index

Most changes need more than one rule file.

Subject Rule file
A feature of the test framework that can already do the work rules/finding-features.md
The layout of the files, the names of the tests, and the groups rules/naming.md
Arrange-act-assert, and the correct assertion for each subject rules/assertions.md
The coverage of an endpoint, the authentication, the authorization, the isolation of a tenant, the validation, and the tests in a browser rules/endpoint-tests.md
The factories, the owner of the test data, and the repeated input values rules/test-data.md
The fakes, the mocks, the outbound HTTP, the time, the randomness, and the database rules/isolation.md
The escaping, the injection, the access across tenants, and the checks of privilege rules/security.md
The settings of the environment and of the CI for a slow suite rules/performance.md
The review of a test or of a suite rules/review.md

Version History

  • f11c94b Current 2026-08-29 02:20

Same Skill Collection

.claude/skills/echo-development/SKILL.md
.claude/skills/laravel-query-builder/SKILL.md
.claude/skills/medialibrary-development/SKILL.md
.claude/skills/socialite-development/SKILL.md
.claude/skills/spatie-javascript/SKILL.md
.claude/skills/spatie-laravel-php/SKILL.md
.claude/skills/spatie-security/SKILL.md
.claude/skills/spatie-version-control/SKILL.md
.github/skills/custom-fields-development/SKILL.md
.github/skills/flowforge-development/SKILL.md
.claude/skills/agent-browser-relaticle/SKILL.md
.claude/skills/ai-sdk-development/SKILL.md
.claude/skills/business-review/SKILL.md
.claude/skills/cashier-stripe-development/SKILL.md
.claude/skills/configuring-horizon/SKILL.md
.claude/skills/fortify-development/SKILL.md
.claude/skills/infer-conventions/SKILL.md
.claude/skills/laravel-best-practices/SKILL.md
.claude/skills/livewire-development/SKILL.md
.claude/skills/mcp-development/SKILL.md
.claude/skills/passport-development/SKILL.md
.claude/skills/pennant-development/SKILL.md
.claude/skills/pest-testing/SKILL.md
.claude/skills/screenshot-with-callout/SKILL.md
.claude/skills/tailwindcss-development/SKILL.md
.github/skills/livewire-development/SKILL.md
.github/skills/manual-testing/SKILL.md
.github/skills/tailwindcss-development/SKILL.md

Metadata

Files
0
Version
f11c94b
Hash
df508023
Indexed
2026-08-29 02:20

Home - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-29 07:45
浙ICP备14020137号-1 $Map of visitor$