Testing

作者 mindrally97184105b5da无许可证269 个星标收录于 2026年10月8日更新于 2026年10月8日仓库5周前更新

General testing best practices and guidelines for writing comprehensive, maintainable tests across different testing frameworks and languages.

AI 生成的概览

提供跨框架和语言的全面、可维护软件测试编写指南。

功能
该技能提供通用的软件测试最佳实践,用于编写、审查或讨论测试。内容涵盖单元测试、测试组织、隔离、测试数据、覆盖率、测试代码质量和断言。它产出的是指导原则和约定,而不是文件或可运行产物。
适用场景
适用于编写或审查测试,或讨论代码库中的测试约定。适合希望统一单元、集成和端到端测试实践的团队。
运行要求
除智能体外无需其他条件;仅为说明性指令,不附带脚本。

Testing Best Practices

You are an expert in software testing best practices. Apply these principles when writing, reviewing, or discussing tests.

Core Testing Principles

Unit Testing

  • Write unit tests using table-driven patterns and parallel execution where appropriate
  • Mock external interfaces cleanly using generated or handwritten mocks
  • Separate fast unit tests from slower integration and E2E tests
  • Ensure test coverage for every exported function, with behavioral checks
  • Use coverage tools to verify adequate coverage

Test Organization

  • Use descriptive and meaningful test names that clearly describe expected behavior
  • Organize tests to mirror your source file structure
  • Group related tests logically using describe/context blocks or equivalent

Test Isolation

  • Each test must be independent; avoid shared state between tests
  • Use fixtures and setup/teardown hooks for clean state management
  • Mock external services (APIs, databases) appropriately

Test Data

  • Prefer factories over fixtures for test data creation
  • Use minimal, necessary setup for each test
  • Generate unique, diverse test data to cover edge cases

Comprehensive Coverage

  • Tests must cover both typical cases and edge cases
  • Include tests for invalid inputs and error conditions
  • Focus on critical user paths that reflect real behavior

Code Quality in Tests

  • Keep test code concise without unnecessary complexity
  • Extract reusable logic into helper functions
  • Share common behaviors across contexts using shared examples
  • Add comments explaining complex test logic

Assertions

  • Use clear, readable assertion syntax
  • Prefer framework-specific assertion methods over generic assert statements
  • Write assertions that clearly communicate intent

来源与署名

来源:mindrally/skills位于testing提交9718410

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架