clean-code-unit-tests

Installation
SKILL.md

Unit Tests

Test code is as important as production code. Tests keep production code flexible, maintainable and reusable, because with a trustworthy suite you aren't afraid to change anything.

The three laws of TDD

  1. Don't write production code until you have a failing unit test.
  2. Don't write more of a test than is enough to fail. A test that doesn't compile counts as failing.
  3. Don't write more production code than is enough to pass the currently failing test.

These keep you in a very short cycle, measured in seconds to minutes, so tests and code grow together and the tests cover nearly everything. When the user practices TDD, follow the cycle: red, green, refactor. When tdd (comes with npx skills-code-kit) is installed, it defines the test-first workflow; this skill defines what a clean test looks like. When TDD/README.md (comes with npx skills-code-kit) is installed, it routes to the TDD pattern skills: which test to write next, how to get to green, and how to refactor afterwards. Otherwise, still write the tests alongside the code, not as an afterthought.

Keep tests clean

Dirty tests are worse than no tests, maybe even more than having none. As production code evolves, messy tests become hard to change. They then turn into a burden, get blamed for slowing the team down, and are eventually thrown away. Without tests, the code rots, because no one dares to clean it.

Hold test code to the same standard as production code: good names, small functions, no duplication and clear structure.

Installs
1
First Seen
2 days ago