Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

testing-anti-patterns

БесплатноБез исполняемых скриптовНе проверен

Use when writing or changing tests, adding mocks - prevents testing mock behavior, production pollution with test-only methods, and mocking without…

withzombiesот withzombies★ 81 звезда на GitHub

Об этом скилле

This skill was ported from Claude Code. In Codex: - "Skill tool" means read the skill's `SKILL.md` from disk. - "TodoWrite" means create and maintain a checklist section in your response. - "Task()" means `spawn_agent` (dispatch in parallel via `multi_tool_use.parallel` when needed). - Claude-specific hooks and slash commands are not available; skip those steps. Tests must verify real behavior, not mock behavior; mocks are tools to isolate, not things to test. LOW FREEDOM - The 3 Iron Laws are absolute (never test mocks, never add test-only methods, never mock without understanding). Apply gate functions strictly. ## The 3 Iron Laws
  1. NEVER test mock behavior → Test real component behavior
  2. NEVER add test-only methods to production → Use test utilities instead
  3. NEVER mock without understanding → Know dependencies before mocking

Gate Functions (Use Before Action)

Before asserting on any mock:

  • Ask: "Am I testing real behavior or mock existence?"
  • If mock existence → STOP, delete assertion

Before adding method to production:

  • Ask: "Is this only used by tests?"
  • If yes → STOP, put in test utilities

Before mocking:

  • Ask: "What side effects does real method have?"
  • Ask: "Does test depend on those side effects?"
  • If depends → Mock lower level, not this method
- Writing new tests - Adding mocks to tests - Tempted to add method only tests will use - Test failing and considering mocking something - Unsure whether to mock a dependency - Test setup becoming complex with mocks

Critical moment: Before you add a mock or test-only method, use this skill's gate functions.

## Law 1: Never Test Mock Behavior

Anti-pattern:

// ❌ BAD: Testing that mock exists
#[test]
fn test_processes_request() {
    let mock_service = MockApiService::new();
    let handler = RequestHandler::new(Box::new(mock_service));

    // Testing mock existence, not behavior
    assert!(handler.service().is_mock());
}

Why wrong: Verifies mock works, not that code works.

Fix:

// ✅ GOOD: Test real behavior
#[test]
fn test_processes_request() {
    let service = TestApiService::new();  // Real implementation or full fake
    let handler = RequestHandler::new(Box::new(service));

    let result = handler.process_request("data");
    assert_eq!(result.status, StatusCode::OK);
}

Law 2: Never Add Test-Only Methods to Production

Anti-pattern:

// ❌ BAD: reset() only used in tests
pub struct Connection {
    pool: Arc<ConnectionPool>,
}

impl Connection {
    pub fn reset(&mut self) {  // Looks like production API!
        self.pool.clear_all();
    }
}

// In tests
#[test]
fn test_something() {
    let mut conn = Connection::new();
    conn.reset();  // Test-only method
}

Why wrong:

  • Production code polluted with test-only methods
  • Dangerous if accidentally called in production
  • Confuses object lifecycle with entity lifecycle

Fix:

// ✅ GOOD: Test utilities handle cleanup
// Connection has no reset()

// In tests/test_utils.rs
pub fn cleanup_connection(conn: &Connection) {
    if let Some(pool) = conn.get_pool() {
        pool.clear_test_data();
    }
}

// In tests
#[test]
fn test_something() {
    let conn = Connection::new();
    cleanup_connection(&conn);
}

Law 3: Never Mock Without Understanding

Anti-pattern:

// ❌ BAD: Mock breaks test logic
#[test]
fn test_detects_duplicate_server() {
    // Mock prevents config write that test depends on!
    let mut config_manager = MockConfigManager::new();
    config_manager.expect_add_server()
        .returning(|_| Ok(()));  // No actual config write!

    config_manager.add_server(&config).unwrap();
    config_manager.add_server(&config).unwrap();  // Should fail - but won't!
}

Why wrong: Mocked method had side effect test depended on (writing config).

Fix:

// ✅ GOOD: Mock at correct level
#[test]
fn test_detects_duplicate_server() {
    // Mock the slow part, preserve behavior test needs
    let server_manager = MockServerManager::new();  // Just mock slow server startup
    let config_manager = ConfigManager::new_with_manager(server_manager);

    config_manager.add_server(&config).unwrap();  // Config written
    let result = config_manager.add_server(&config);  // Duplicate detected ✓
    assert!(result.is_err());
}
## Gate Function 1: Before Asserting on Mock
BEFORE any assertion that checks mock elements:

1. Ask: "Am I testing real component behavior or just mock existence?"

2. If testing mock existence:
   STOP - Delete the assertion or unmock the component

3. Test real behavior instead

Examples of mock existence testing (all wrong):

  • assert!(handler.service().is_mock())
  • `XCTAssertTrue(m
Полный SKILL.md на GitHub

Установить testing-anti-patterns в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

agents/openai.yaml

FAQ

Что делает скилл testing-anti-patterns?

Use when writing or changing tests, adding mocks - prevents testing mock behavior, production pollution with test-only methods, and mocking without understanding dependencies

Как установить скилл testing-anti-patterns?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл testing-anti-patterns запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить testing-anti-patterns с