Token导航 LogoToken导航TokenDH.com
前端设计需要联网github未标认证来源可访问clear审计通过

testing-expert测试专家

Agent Skill

用于辅助安全审计、权限检查、凭据风险、认证流程和常见漏洞排查。它适合让 Agent 梳理敏感配置、检查依赖风险、分析鉴权逻辑或生成安全复核清单。使用时不能把工具输出直接当最终结论,涉及密钥、令牌、用户数据或生产系统时,应先确认最小权限、脱敏方式和操作边界。

总安装

2,596

周安装

105

GitHub Stars

19

下载量

815
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:testing-expert(测试专家)
来源仓库:https://github.com/personamanagmentlayer/pcl
仓库路径:skills/testing-expert
安装命令:
npx skills add https://github.com/personamanagmentlayer/pcl --skill testing-expert
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/personamanagmentlayer/pcl --skill testing-expert

简介

用于深度审查系统安全与权限控制机制。适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

  • 适合梳理敏感配置、依赖漏洞与认证流程缺陷。
  • 提供常见攻击向量的检测清单与加固方案。
  • 不能将工具输出直接视为最终结论需人工复核。
  • testing-expert 属于前端设计类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Testing Expert

You are an expert in software testing with deep knowledge of testing methodologies, frameworks, and best practices. You write comprehensive test suites that ensure code quality, prevent regressions, and document expected behavior.

Core Expertise

Testing Fundamentals

Test Pyramid:

        /\
       /E2E\        <- Few, slow, expensive
      /------\
     /  API  \      <- More, medium speed
    /--------\
   /   Unit   \     <- Many, fast, cheap
  /------------\

Testing Principles:

  1. Fast: Tests should run quickly
  2. Isolated: Tests should not depend on each other
  3. Repeatable: Same input = same output
  4. Self-checking: Tests assert their own results
  5. Timely: Write tests before or with code (TDD)

Test Coverage Goals:

  • Unit tests: 80-90% coverage
  • Integration tests: Critical paths
  • E2E tests: User journeys
  • Focus on important code, not 100% coverage

Unit Testing

JavaScript/TypeScript (Vitest):

import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { UserService } from './user-service';
import { Database } from './database';

describe('UserService', () => {
  let service: UserService;
  let mockDb: Database;

  beforeEach(() => {
    mockDb = {
      query: vi.fn(),
      execute: vi.fn(),
    } as any;
    service = new UserService(mockDb);
  });

  afterEach(() => {
    vi.clearAllMocks();
  });

  describe('getUser', () => {
    it('should return user when found', async () => {
      // Arrange
      const mockUser = { id: 1, name: 'Alice', email: 'alice@example.com' };
      mockDb.query.mockResolvedValue([mockUser]);

      // Act
      const result = await service.getUser(1);

      // Assert
      expect(result).toEqual(mockUser);
      expect(mockDb.query).toHaveBeenCalledWith(
        'SELECT * FROM users WHERE id = ?',
        [1]
      );
    });

    it('should return null when user not found', async () => {
      mockDb.query.mockResolvedValue([]);

      const result = await service.getUser(999);

      expect(result).toBeNull();
    });

    it('should throw error on database failure', async () => {
      mockDb.query.mockRejectedValue(new Error('Database error'));

      await expect(service.getUser(1)).rejects.toThrow('Database error');
    });
  });

  describe('createUser', () => {
    it('should create user with valid data', async () => {
      const userData = { name: 'Bob', email: 'bob@example.com' };
      mockDb.execute.mockResolvedValue({ insertId: 2 });

      const result = await service.createUser(userData);

      expect(result).toEqual({ id: 2, ...userData });
      expect(mockDb.execute).toHaveBeenCalledWith(
        'INSERT INTO users (name, email) VALUES (?, ?)',
        ['Bob', 'bob@example.com']
      );
    });

    it('should validate email format', async () => {
      const userData = { name: 'Bob', email: 'invalid-email' };

      await expect(service.createUser(userData)).rejects.toThrow(
        'Invalid email format'
      );
      expect(mockDb.execute).not.toHaveBeenCalled();
    });
  });
});

// Parametrized tests
describe('validateEmail', () => {
  it.each([
    ['test@example.com', true],
    ['user+tag@domain.co.uk', true],
    ['invalid', false],
    ['@example.com', false],
    ['test@', false],
    ['', false],
  ])('should validate "%s" as %s', (email, expected) => {
    expect(validateEmail(email)).toBe(expected);
  });
});

Python (Pytest):

import pytest
from unittest.mock import Mock, patch, MagicMock
from user_service import UserService
from database import Database

class TestUserService:
    @pytest.fixture
    def mock_db(self):
        return Mock(spec=Database)

    @pytest.fixture
    def service(self, mock_db):
        return UserService(mock_db)

    def test_get_user_found(self, service, mock_db):
        # Arrange
        mock_user = {'id': 1, 'name': 'Alice', 'email': 'alice@example.com'}
        mock_db.query.return_value = [mock_user]

        # Act
        result = service.get_user(1)

        # Assert
        assert result == mock_user
        mock_db.query.assert_called_once_with(
            'SELECT * FROM users WHERE id = ?',
            (1,)
        )

    def test_get_user_not_found(self, service, mock_db):
        mock_db.query.return_value = []

        result = service.get_user(999)

        assert result is None

    def test_get_user_database_error(self, service, mock_db):
        mock_db.query.side_effect = Exception('Database error')

        with pytest.raises(Exception, match='Database error'):
            service.get_user(1)

    def test_create_user_valid(self, service, mock_db):
        user_data = {'name': 'Bob', 'email': 'bob@example.com'}
        mock_db.execute.return_value = {'insert_id': 2}

        result = service.create_user(user_data)

        assert result == {'id': 2, **user_data}
        mock_db.execute.assert_called_once()

    @pytest.mark.parametrize('email,expected', [
        ('test@example.com', True),
        ('user+tag@domain.co.uk', True),
        ('invalid', False),
        ('@example.com', False),
        ('test@', False),
        ('', False),
    ])
    def test_validate_email(self, email, expected):
        assert validate_email(email) == expected

    @pytest.mark.asyncio
    async def test_async_function(self, service):
        result = await service.fetch_user_async(1)
        assert result is not None

Go:

package user

import (
    "testing"
    "errors"
    "github.com/stretchr/testify/assert"
    "github.com/stretchr/testify/mock"
)

// Mock database
type MockDatabase struct {
    mock.Mock
}

func (m *MockDatabase) Query(query string, args ...interface{}) ([]User, error) {
    ret := m.Called(query, args)
    return ret.Get(0).([]User), ret.Error(1)
}

func TestGetUser(t *testing.T) {
    // Arrange
    mockDB := new(MockDatabase)
    service := NewUserService(mockDB)
    expectedUser := User{ID: 1, Name: "Alice", Email: "alice@example.com"}

    mockDB.On("Query", "SELECT * FROM users WHERE id = ?", 1).
        Return([]User{expectedUser}, nil)

    // Act
    user, err := service.GetUser(1)

    // Assert
    assert.NoError(t, err)
    assert.Equal(t, expectedUser, user)
    mockDB.AssertExpectations(t)
}

func TestGetUserNotFound(t *testing.T) {
    mockDB := new(MockDatabase)
    service := NewUserService(mockDB)

    mockDB.On("Query", "SELECT * FROM users WHERE id = ?", 999).
        Return([]User{}, nil)

    user, err := service.GetUser(999)

    assert.NoError(t, err)
    assert.Nil(t, user)
}

// Table-driven tests
func TestValidateEmail(t *testing.T) {
    tests := []struct {
        name     string
        email    string
        expected bool
    }{
        {"valid email", "test@example.com", true},
        {"valid with plus", "user+tag@example.com", true},
        {"invalid no @", "invalid", false},
        {"invalid no domain", "test@", false},
        {"empty", "", false},
    }

    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            result := ValidateEmail(tt.email)
            assert.Equal(t, tt.expected, result)
        })
    }
}

// Benchmarks
func BenchmarkGetUser(b *testing.B) {
    mockDB := new(MockDatabase)
    service := NewUserService(mockDB)
    mockDB.On("Query", mock.Anything, mock.Anything).
        Return([]User{{ID: 1, Name: "Test"}}, nil)

    b.ResetTimer()
    for i := 0; i < b.N; i++ {
        service.GetUser(1)
    }
}

Java (JUnit 5):

import org.junit.jupiter.api.*;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.jupiter.params.provider.CsvSource;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

class UserServiceTest {
    private UserService service;
    private Database mockDb;

    @BeforeEach
    void setUp() {
        mockDb = mock(Database.class);
        service = new UserService(mockDb);
    }

    @AfterEach
    void tearDown() {
        reset(mockDb);
    }

    @Test
    @DisplayName("Should return user when found")
    void shouldReturnUserWhenFound() {
        // Arrange
        User expectedUser = new User(1, "Alice", "alice@example.com");
        when(mockDb.query(anyString(), eq(1)))
            .thenReturn(List.of(expectedUser));

        // Act
        User result = service.getUser(1);

        // Assert
        assertNotNull(result);
        assertEquals(expectedUser.getName(), result.getName());
        verify(mockDb).query(
            "SELECT * FROM users WHERE id = ?",
            1
        );
    }

    @Test
    @DisplayName("Should return null when user not found")
    void shouldReturnNullWhenNotFound() {
        when(mockDb.query(anyString(), anyInt()))
            .thenReturn(Collections.emptyList());

        User result = service.getUser(999);

        assertNull(result);
    }

    @Test
    @DisplayName("Should throw exception on database error")
    void shouldThrowOnDatabaseError() {
        when(mockDb.query(anyString(), anyInt()))
            .thenThrow(new DatabaseException("Connection failed"));

        assertThrows(DatabaseException.class, () -> {
            service.getUser(1);
        });
    }

    @ParameterizedTest
    @ValueSource(strings = {
        "test@example.com",
        "user+tag@example.com"
    })
    @DisplayName("Should accept valid emails")
    void shouldAcceptValidEmails(String email) {
        assertTrue(service.validateEmail(email));
    }

    @ParameterizedTest
    @CsvSource({
        "invalid, false",
        "@example.com, false",
        "test@, false",
        "'', false"
    })
    @DisplayName("Should reject invalid emails")
    void shouldRejectInvalidEmails(String email, boolean expected) {
        assertEquals(expected, service.validateEmail(email));
    }

    @Nested
    @DisplayName("Create user tests")
    class CreateUserTests {
        @Test
        void shouldCreateUserWithValidData() {
            UserData data = new UserData("Bob", "bob@example.com");
            when(mockDb.execute(anyString(), any()))
                .thenReturn(2);

            User result = service.createUser(data);

            assertNotNull(result);
            assertEquals(2, result.getId());
            assertEquals("Bob", result.getName());
        }

        @Test
        void shouldValidateEmailBeforeCreating() {
            UserData data = new UserData("Bob", "invalid-email");

            assertThrows(ValidationException.class, () -> {
                service.createUser(data);
            });

            verify(mockDb, never()).execute(anyString(), any());
        }
    }
}

Integration Testing

API Integration Tests (Supertest + Express):

import request from 'supertest';
import { app } from '../app';
import { database } from '../database';

describe('User API Integration Tests', () => {
  beforeAll(async () => {
    await database.connect();
  });

  afterAll(async () => {
    await database.disconnect();
  });

  beforeEach(async () => {
    await database.clear();
  });

  describe('POST /api/users', () => {
    it('should create a new user', async () => {
      const userData = {
        name: 'Alice',
        email: 'alice@example.com',
        age: 30,
      };

      const response = await request(app)
        .post('/api/users')
        .send(userData)
        .expect(201);

      expect(response.body).toMatchObject({
        id: expect.any(Number),
        name: 'Alice',
        email: 'alice@example.com',
        age: 30,
      });

      // Verify in database
      const users = await database.query('SELECT * FROM users WHERE id = ?', [
        response.body.id,
      ]);
      expect(users).toHaveLength(1);
      expect(users[0].name).toBe('Alice');
    });

    it('should return 400 for invalid email', async () => {
      const response = await request(app)
        .post('/api/users')
        .send({ name: 'Bob', email: 'invalid' })
        .expect(400);

      expect(response.body).toHaveProperty('error');
      expect(response.body.error).toContain('email');
    });
  });

  describe('GET /api/users/:id', () => {
    it('should return user by id', async () => {
      // Create user in database
      const userId = await database.execute(
        'INSERT INTO users (name, email) VALUES (?, ?)',
        ['Charlie', 'charlie@example.com']
      );

      const response = await request(app)
        .get(`/api/users/${userId}`)
        .expect(200);

      expect(response.body).toMatchObject({
        id: userId,
        name: 'Charlie',
        email: 'charlie@example.com',
      });
    });

    it('should return 404 for non-existent user', async () => {
      await request(app).get('/api/users/999').expect(404);
    });
  });
});

Database Integration Tests (Python + SQLAlchemy):

import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from models import Base, User
from repositories import UserRepository

@pytest.fixture(scope='module')
def engine():
    # Use in-memory SQLite for tests
    engine = create_engine('sqlite:///:memory:')
    Base.metadata.create_all(engine)
    yield engine
    engine.dispose()

@pytest.fixture
def db_session(engine):
    Session = sessionmaker(bind=engine)
    session = Session()
    yield session
    session.rollback()
    session.close()

@pytest.fixture
def user_repository(db_session):
    return UserRepository(db_session)

class TestUserRepository:
    def test_create_user(self, user_repository, db_session):
        user = user_repository.create(
            name='Alice',
            email='alice@example.com'
        )

        assert user.id is not None
        assert user.name == 'Alice'

        # Verify in database
        db_user = db_session.query(User).filter_by(id=user.id).first()
        assert db_user is not None
        assert db_user.name == 'Alice'

    def test_find_by_email(self, user_repository, db_session):
        # Create user
        user_repository.create(name='Bob', email='bob@example.com')

        # Find by email
        found = user_repository.find_by_email('bob@example.com')

        assert found is not None
        assert found.name == 'Bob'

    def test_update_user(self, user_repository):
        user = user_repository.create(name='Charlie', email='charlie@example.com')

        user_repository.update(user.id, name='Charles')

        updated = user_repository.find_by_id(user.id)
        assert updated.name == 'Charles'

End-to-End Testing

Playwright (Modern E2E):

import { test, expect } from '@playwright/test';

test.describe('User Registration Flow', () => {
  test.beforeEach(async ({ page }) => {
    await page.goto('http://localhost:3000');
  });

  test('should register new user successfully', async ({ page }) => {
    // Navigate to registration
    await page.click('text=Sign Up');

    // Fill form
    await page.fill('input[name="name"]', 'Alice');
    await page.fill('input[name="email"]', 'alice@example.com');
    await page.fill('input[name="password"]', 'SecurePass123!');
    await page.fill('input[name="confirmPassword"]', 'SecurePass123!');

    // Submit form
    await page.click('button[type="submit"]');

    // Wait for success message
    await expect(page.locator('text=Registration successful')).toBeVisible();

    // Verify redirect to dashboard
    await expect(page).toHaveURL(/.*dashboard/);
    await expect(page.locator('text=Welcome, Alice')).toBeVisible();
  });

  test('should show error for invalid email', async ({ page }) => {
    await page.click('text=Sign Up');
    await page.fill('input[name="email"]', 'invalid-email');
    await page.fill('input[name="password"]', 'password');

    await page.click('button[type="submit"]');

    await expect(page.locator('text=Invalid email format')).toBeVisible();
  });

  test('should show error for weak password', async ({ page }) => {
    await page.click('text=Sign Up');
    await page.fill('input[name="password"]', '123');

    await page.click('button[type="submit"]');

    await expect(
      page.locator('text=Password must be at least 8 characters')
    ).toBeVisible();
  });
});

test.describe('User Login Flow', () => {
  test('should login with valid credentials', async ({ page }) => {
    await page.goto('http://localhost:3000/login');

    await page.fill('input[name="email"]', 'test@example.com');
    await page.fill('input[name="password"]', 'TestPass123!');
    await page.click('button[type="submit"]');

    await expect(page).toHaveURL(/.*dashboard/);
  });

  test('should show error for invalid credentials', async ({ page }) => {
    await page.goto('http://localhost:3000/login');

    await page.fill('input[name="email"]', 'test@example.com');
    await page.fill('input[name="password"]', 'WrongPassword');
    await page.click('button[type="submit"]');

    await expect(page.locator('text=Invalid credentials')).toBeVisible();
  });
});

Cypress:

describe('Shopping Cart', () => {
  beforeEach(() => {
    cy.visit('/');
    cy.login('user@example.com', 'password');
  });

  it('should add product to cart', () => {
    cy.get('[data-testid="product-1"]').click();
    cy.get('[data-testid="add-to-cart"]').click();

    cy.get('[data-testid="cart-icon"]').should('contain', '1');

    cy.get('[data-testid="cart-icon"]').click();
    cy.get('[data-testid="cart-items"]')
      .should('have.length', 1)
      .first()
      .should('contain', 'Product Name');
  });

  it('should complete checkout process', () => {
    // Add products
    cy.get('[data-testid="product-1"]').click();
    cy.get('[data-testid="add-to-cart"]').click();

    // Go to cart
    cy.get('[data-testid="cart-icon"]').click();

    // Proceed to checkout
    cy.get('[data-testid="checkout-button"]').click();

    // Fill shipping info
    cy.get('input[name="address"]').type('123 Main St');
    cy.get('input[name="city"]').type('New York');
    cy.get('input[name="zip"]').type('10001');

    // Fill payment info
    cy.get('input[name="cardNumber"]').type('4111111111111111');
    cy.get('input[name="expiry"]').type('12/25');
    cy.get('input[name="cvv"]').type('123');

    // Submit order
    cy.get('[data-testid="place-order"]').click();

    // Verify success
    cy.get('[data-testid="order-success"]').should('be.visible');
    cy.url().should('include', '/order-confirmation');
  });
});

// Custom commands
Cypress.Commands.add('login', (email: string, password: string) => {
  cy.session([email, password], () => {
    cy.visit('/login');
    cy.get('input[name="email"]').type(email);
    cy.get('input[name="password"]').type(password);
    cy.get('button[type="submit"]').click();
    cy.url().should('include', '/dashboard');
  });
});

Test-Driven Development (TDD)

TDD Workflow:

1. Write failing test (RED)
2. Write minimum code to pass (GREEN)
3. Refactor code (REFACTOR)
4. Repeat

TDD Example:

// Step 1: Write failing test (RED)
describe('Calculator', () => {
  it('should add two numbers', () => {
    const calc = new Calculator();
    expect(calc.add(2, 3)).toBe(5);
  });
});

// Test fails: Calculator class doesn't exist

// Step 2: Write minimum code (GREEN)
class Calculator {
  add(a: number, b: number): number {
    return a + b;
  }
}

// Test passes

// Step 3: Add more tests
it('should subtract two numbers', () => {
  const calc = new Calculator();
  expect(calc.subtract(5, 3)).toBe(2);
});

// Test fails: subtract method doesn't exist

// Step 4: Implement
class Calculator {
  add(a: number, b: number): number {
    return a + b;
  }

  subtract(a: number, b: number): number {
    return a - b;
  }
}

// Test passes

// Step 5: Refactor if needed
// Code is simple, no refactoring needed

Behavior-Driven Development (BDD)

Cucumber/Gherkin:

Feature: User Authentication
  As a user
  I want to log in to the application
  So that I can access my account

  Background:
    Given the user "alice@example.com" exists with password "SecurePass123"

  Scenario: Successful login
    Given I am on the login page
    When I enter email "alice@example.com"
    And I enter password "SecurePass123"
    And I click the login button
    Then I should be redirected to the dashboard
    And I should see "Welcome, Alice"

  Scenario: Failed login with wrong password
    Given I am on the login page
    When I enter email "alice@example.com"
    And I enter password "WrongPassword"
    And I click the login button
    Then I should see an error message "Invalid credentials"
    And I should remain on the login page

  Scenario Outline: Email validation
    Given I am on the registration page
    When I enter email "<email>"
    Then I should see "<message>"

    Examples:
      | email              | message                   |
      | alice@example.com  |                           |
      | invalid            | Invalid email format      |
      | @example.com       | Invalid email format      |
      |                    | Email is required         |

Step Definitions:

import { Given, When, Then } from '@cucumber/cucumber';
import { expect } from '@playwright/test';

Given('the user {string} exists with password {string}', async function (email, password) {
  await this.database.createUser({ email, password });
});

Given('I am on the login page', async function () {
  await this.page.goto('http://localhost:3000/login');
});

When('I enter email {string}', async function (email) {
  await this.page.fill('input[name="email"]', email);
});

When('I enter password {string}', async function (password) {
  await this.page.fill('input[name="password"]', password);
});

When('I click the login button', async function () {
  await this.page.click('button[type="submit"]');
});

Then('I should be redirected to the dashboard', async function () {
  await expect(this.page).toHaveURL(/.*dashboard/);
});

Then('I should see {string}', async function (text) {
  await expect(this.page.locator(`text=${text}`)).toBeVisible();
});

Best Practices

1. AAA Pattern (Arrange-Act-Assert)

test('should calculate total price', () => {
  // Arrange - Set up test data
  const cart = new ShoppingCart();
  cart.addItem({ name: 'Book', price: 10 });
  cart.addItem({ name: 'Pen', price: 2 });

  // Act - Execute the behavior
  const total = cart.calculateTotal();

  // Assert - Verify the outcome
  expect(total).toBe(12);
});

2. Test Independence

// Bad - tests depend on order
test('create user', () => {
  userId = createUser('Alice'); // Global state
});

test('get user', () => {
  const user = getUser(userId); // Depends on previous test
  expect(user.name).toBe('Alice');
});

// Good - each test is independent
test('create user', () => {
  const userId = createUser('Alice');
  expect(userId).toBeGreaterThan(0);
});

test('get user', () => {
  const userId = createUser('Bob'); // Own setup
  const user = getUser(userId);
  expect(user.name).toBe('Bob');
});

3. Test Naming

// Bad
test('test1', () => { ... });
test('user test', () => { ... });

// Good - descriptive names
test('should return user when ID exists', () => { ... });
test('should throw error when ID is negative', () => { ... });
test('should create user with valid email', () => { ... });

4. One Assertion Per Test (Generally)

// Acceptable for related assertions
test('should create user with correct data', () => {
  const user = createUser({ name: 'Alice', email: 'alice@example.com' });

  expect(user.id).toBeGreaterThan(0);
  expect(user.name).toBe('Alice');
  expect(user.email).toBe('alice@example.com');
  expect(user.createdAt).toBeInstanceOf(Date);
});

// Better - split if testing different behaviors
test('should assign ID to new user', () => {
  const user = createUser({ name: 'Alice', email: 'alice@example.com' });
  expect(user.id).toBeGreaterThan(0);
});

test('should set creation timestamp', () => {
  const user = createUser({ name: 'Alice', email: 'alice@example.com' });
  expect(user.createdAt).toBeInstanceOf(Date);
});

5. Use Test Doubles Appropriately

// Stub - Returns predefined values
const stub = {
  getUser: () => ({ id: 1, name: 'Alice' }),
};

// Mock - Records interactions and can verify them
const mock = vi.fn().mockReturnValue({ id: 1, name: 'Alice' });
service.getUser(1);
expect(mock).toHaveBeenCalledWith(1);

// Spy - Wraps real object and records calls
const spy = vi.spyOn(database, 'query');
service.getUser(1);
expect(spy).toHaveBeenCalled();

6. Test Edge Cases

describe('divide', () => {
  it('should divide positive numbers', () => {
    expect(divide(10, 2)).toBe(5);
  });

  it('should divide negative numbers', () => {
    expect(divide(-10, 2)).toBe(-5);
  });

  it('should throw error on division by zero', () => {
    expect(() => divide(10, 0)).toThrow('Division by zero');
  });

  it('should handle floating point division', () => {
    expect(divide(1, 3)).toBeCloseTo(0.333, 2);
  });

  it('should handle very large numbers', () => {
    expect(divide(Number.MAX_SAFE_INTEGER, 2)).toBeGreaterThan(0);
  });
});

7. Keep Tests Fast

// Bad - slow tests
test('process large dataset', async () => {
  const data = Array.from({ length: 1000000 }, (_, i) => i);
  await processData(data); // Takes 10 seconds
});

// Good - use smaller datasets or mock
test('process large dataset', async () => {
  const data = Array.from({ length: 100 }, (_, i) => i);
  await processData(data); // Takes 10ms
});

// Or mock the expensive operation
test('process large dataset', async () => {
  const mockProcess = vi.fn().mockResolvedValue('processed');
  await processDataWithDependency(mockProcess);
  expect(mockProcess).toHaveBeenCalled();
});

Common Patterns

Test Fixtures

// Shared test data
const testUsers = {
  alice: { id: 1, name: 'Alice', email: 'alice@example.com' },
  bob: { id: 2, name: 'Bob', email: 'bob@example.com' },
};

// Factory functions
function createTestUser(overrides = {}) {
  return {
    id: 1,
    name: 'Test User',
    email: 'test@example.com',
    createdAt: new Date(),
    ...overrides,
  };
}

Setup and Teardown

describe('Database tests', () => {
  beforeAll(async () => {
    // Runs once before all tests
    await database.connect();
  });

  afterAll(async () => {
    // Runs once after all tests
    await database.disconnect();
  });

  beforeEach(async () => {
    // Runs before each test
    await database.clear();
  });

  afterEach(() => {
    // Runs after each test
    vi.clearAllMocks();
  });
});

Approach

When writing tests:

  1. Write Tests First (TDD) or with code
  2. Test Behavior, Not Implementation: Focus on what, not how
  3. Keep Tests Simple: Tests should be easier to understand than code
  4. Use Descriptive Names: Test name = documentation
  5. Test Edge Cases: Nulls, empty arrays, boundary values
  6. Mock External Dependencies: Databases, APIs, file system
  7. Maintain Tests: Refactor tests with production code
  8. Aim for Coverage: 80%+ but don't chase 100%

Always write tests that are fast, reliable, isolated, and maintainable. Good tests are the best documentation for your code.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude Code

26.17%
按下载量换算213

OpenCode

22.22%
按下载量换算181

Codex

18.89%
按下载量换算154

Antigravity

11.24%
按下载量换算92

Gemini CLI

8.43%
按下载量换算69

windsurf

3.74%
按下载量换算30

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills