Skip to content
Back to skills

Writing Tests

ASecurity

Add or extend automated tests — when asked to cover a function, write a test for a fix, raise coverage, or "check that this works". Also when a change lands with no test at all.

  • 2 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added October 3, 2026
ai-agentsgotesting

Security analysis

A100/100

Scanned October 3, 2026

npx -y skills add ivanvp91/TRCode --skill writing-tests --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Writing Tests?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Writing Tests
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ivanvp91-writing-tests/badge)](https://www.skillsdirectory.com/skills/ivanvp91-writing-tests)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: writing-tests
description: Add or extend automated tests — when asked to cover a function, write a test for a fix, raise coverage, or "check that this works". Also when a change lands with no test at all.
description_ru: Добавить или расширить автотесты — когда просят покрыть функцию, написать тест к исправлению, поднять покрытие, «проверь, что это работает». А также когда изменение приходит вообще без теста.
triggers: тест, тесты, тестов, тестирование, unit test, юнит, test coverage, покрытие, напиши тесты, write tests, vitest, jest, pytest, мок, mock, фикстура, fixture
---

# Writing tests

## 1. Copy the local convention
Before writing a line: find an existing test for something similar. Use the same runner, the same file location and naming, the same assertion style, the same fixture helpers. Check `package.json` scripts / Makefile for how tests are actually run — then run them once to confirm the suite is green to start with.

## 2. Decide what is worth testing
Test the contract, not the implementation:
- The happy path, once.
- The boundaries: empty, one, many, zero, negative, maximum length.
- The error paths: bad input, missing file, rejected promise, timeout.
- The bug you just fixed — a test that fails on the old code.

Skip tests that only restate the code (`expect(add(1,1)).toBe(2)` next to `a+b`) and tests that assert on private internals.

## 3. Shape of a good test
- One behaviour per test; the name says the behaviour: `returns null when the config file is missing`.
- Arrange / act / assert, visibly separated.
- No shared mutable state between tests, no dependence on execution order.
- Deterministic: pin time, seed randomness, never hit the real network.
- Assert on the specific value, not merely that something is truthy.

## 4. Mock as little as possible
Prefer real objects and temp directories over mocks. Mock only what is slow, external, or non-deterministic. A test that mocks the thing under test proves nothing.

## 5. Verify the test is real
Break the production code on purpose (or check out the pre-fix state) and confirm the new test fails. A test that passes against broken code is worse than no test. Then restore and run the full suite.

## What not to do
- Do not change production code to make it easier to test without saying so.
- Do not chase a coverage number by testing getters.
- Do not leave `.only`, `.skip`, stray console output or committed fixtures nobody reads.

## Answer format
- Which files were added/changed and what each test asserts, in one line each.
- The command to run them, with its actual output.
- Gaps you left uncovered and why.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…