SuperAPI AI Directory

test-writer

Testing & quality

View repository

Updated 10-15 21:48

About this skill

Test Writing Skills

Overview

This skill helps you write various types of tests, including unit tests, integration tests, and end-to-end tests.

Keywords: test writing, unit testing, integration testing, end-to-end testing, test cases, test frameworks

Core Features

1. Unit Test Writing

  • Write unit tests for functions and classes
  • Design test cases to cover various scenarios
  • Use Mocks and Stubs to isolate dependencies
  • Ensure test independence and repeatability

2. Integration Test Design

  • Write integration tests between modules
  • Test API interfaces and database interactions
  • Verify the collaboration of system components
  • Design test data and test environments

3. End-to-End Testing

  • Write complete user flow tests
  • Test key business scenarios
  • Verify end-to-end system functionality
  • Use automated testing tools

4. Testing Tools and Frameworks

  • Support mainstream testing frameworks (JUnit, pytest, Jest, etc.)
  • Generate test reports and coverage reports
  • Create test configurations and test environments
  • Design test data and Fixtures

Usage Guide

Test Writing Principles

  1. Comprehensiveness: Cover normal flows, boundary cases, and exception cases
  2. Independence: Each test should run independently and not depend on other tests
  3. Repeatability: Test results should be consistent and not affected by the environment
  4. Clarity: Test code should be clear and easy to understand
  5. Speed: Tests should execute quickly

Test Case Design

  • Normal Scenarios: Test normal functional flows
  • Boundary Cases: Test boundary values and extreme cases
  • Exception Cases: Test error handling and exception cases
  • Performance Testing: Test performance and load (if needed)

Test Coverage

  • Target coverage: above 80% (according to project requirements)
  • Critical paths: 100% coverage
  • Boundary cases: focus on coverage
  • Exception handling: ensure coverage

Output Format

Test code should include:

  • Test Files: Complete test code files
  • Test Cases: Clear test cases and descriptions
  • Test Data: Test data and Fixtures
  • Test Configuration: Test configuration files
  • Test Reports: Test execution results and coverage

Best Practices

  • Use the AAA pattern (Arrange-Act-Assert)
  • Test names should describe what is being tested
  • One test should test only one functional point
  • Use Mocks to isolate external dependencies
  • Keep test code concise
  • Run tests regularly to ensure they pass
  • Pay attention to test coverage, but do not blindly pursue 100%

Common Gotchas

  1. Version Compatibility: Note the compatibility between the framework version and dependency libraries; APIs may differ across versions.
  2. Configuration File Format: Configuration file format errors are the most common issue; it is recommended to use your editor's syntax checking.
  3. Environment Variables: Ensure all necessary environment variables are set correctly, and do not hardcode sensitive information.
  4. Dependency Conflicts: When multiple versions coexist, watch out for dependency conflicts and use a lock file to pin versions.
  5. Performance Pitfalls: In large data volume scenarios, pay attention to performance optimization and avoid common issues such as N+1 queries.

Usage Flow

Step 1: Environment Preparation

Ensure the development environment has the necessary dependencies and tools installed.

Step 2: Configuration Initialization

Perform basic configuration according to project requirements.

Step 3: Using Core Features

Implement the core features according to the example code.

Step 4: Testing and Verification

Run tests to ensure the functionality works properly.

Step 5: Deployment and Release

After development is complete, deploy and monitor.