Unit Test

Unit testing techniques, mocking, and assertions

DongDuong2001 963f683 812 B Updated

File contents

Unit Test Skill

This skill focuses on writing fast, isolated tests for individual units of code (functions, methods, classes).

When to use this skill

  • When writing tests for utility functions, algorithms, or standalone classes.
  • When using tools like Jest, pytest, JUnit, or xUnit.
  • When needing to mock out dependencies (databases, APIs, file systems).

Guidelines

  • Isolation: A unit test should not rely on an external database or network. Use mocks or stubs instead.
  • Naming: Use clear, descriptive names (e.g., calculateTotal_withValidInput_returnsCorrectSum).
  • Structure: Use the Arrange-Act-Assert (AAA) pattern.
  • Speed: Unit tests must be fast so developers can run them frequently.

DongDuong2001/pudo-code-system/tree/main/skills/test/unit-test commit 963f683ff1

Frequently asked questions

npx skillmds@latest add dongduong2001/unit-test