testing

A set of software testing practices built around a testing pyramid: many fast unit tests, fewer integration tests, and a small number of end-to-end tests. Unit tests check one small piece, integration tests check components together, and end-to-end tests check a complete user flow.

In plain words
What is it for?
Use it when planning test coverage or writing unit tests with mocks and stubs. It includes examples for checking valid inputs, errors, missing data, and expected results.
Why use it?
It helps choose the right test level and write tests that are easier to run, understand, and maintain. It also standardizes test names and the Arrange-Act-Assert structure.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/mywand/cusrsor-do-it/testing
Clone the repo
git clone --depth 1 https://github.com/mywand/cusrsor-do-it

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 3,518 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.03518
Opus 5 $0.00000 $0.01759
Sonnet 5 $0.00000 $0.00704
Haiku 4.5 $0.00000 $0.00352

Measured yesterday against content hash d62ac22e7a13, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

testing scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

response = requests.post(
.cursor/rules/tools/testing.mdc · 515 lines

How it starts

The opening of the file, as written. The whole thing — 515 lines — stays where its author put it; the contents beside it link to each section on GitHub.

最近更新: 2025-10-10

测试策略与最佳实践

1. 测试金字塔

1.1 测试层级

    /\
   /  \
  / UI \     <- 少量 E2E 测试
 /______\
/        \
| 集成测试 |   <- 适量集成测试
|________|
|        |
| 单元测试 |   <- 大量单元测试
|________|

1.2 测试比例建议

  • 单元测试: 70% - 快速、稳定、易维护
  • 集成测试: 20% - 测试组件间交互
  • 端到端测试: 10% - 测试完整用户流程

2. 单元测试

2.1 测试命名规范

// 格式: 方法名_测试场景_期望结果
describe('UserService', () => {
  describe('getUserById', () => {
    it('should return user when valid id provided', () => {
      // 测试逻辑
    })
    
    it('should throw error when invalid id provided', () => {
      // 测试逻辑
    })
    
    it('should return null when user not found', () => {
      // 测试逻辑
    })
  })
})

2.2 AAA 模式 (Arrange-Act-Assert)

def test_calculate_discount_with_valid_inputs():
    # Arrange - 准备测试数据
    price = 100
    discount_rate = 0.1
    expected_discount = 10
    
    # Act - 执行被测试的方法
    actual_discount = calculate_discount(price, discount_rate)
    
    # Assert - 验证结果
    assert actual_discount == expected_discount

2.3 Mock 和 Stub 使用

@Test
public void shouldCreateUserSuccessfully() {
    // Arrange
    CreateUserRequest request = new CreateUserRequest("张三", "[email protected]");
    User expectedUser = new User(1, "张三", "[email protected]");
    
    // Mock 外部依赖
    when(userRepository.save(any(User.class))).thenReturn(expectedUser);
    when(emailService.sendWelcomeEmail(anyString())).thenReturn(true);
    
    // Act
    User actualUser = userService.createUser(request);
    
    // Assert
    assertEquals(expectedUser.getName(), actualUser.getName());
    assertEquals(expectedUser.getEmail(), actualUser.getEmail());
    
    // 验证交互
    verify(userRepository).save(any(User.class));
    verify(emailService).sendWelcomeEmail("[email protected]");
}

2.4 边界测试

describe('validateAge', () => {
  it('should accept minimum valid age', () => {
    expect(validateAge(0)).toBe(true)
  })
  
  it('should accept maximum valid age', () => {
    expect(validateAge(150)).toBe(true)
  })
  
  it('should reject negative age', () => {
    expect(() => validateAge(-1)).toThrow('年龄不能为负数')
  })
  
  it('should reject age over limit', () => {
    expect(() => validateAge(151)).toThrow('年龄不能超过150岁')
  })
  
  it('should handle null input', () => {
    expect(() => validateAge(null)).toThrow('年龄不能为空')
  })
})

Read the full file on GitHub · 515 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 515 lines · 0 tokens per session scan A d62ac22e7a13

Subscribe to this mod's changes

testing is a cursor rule published in the GitHub repository mywand/cusrsor-do-it (2 stars, last pushed 7mo ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 3,518 tokens. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.