# Add Unit Test

> Write a unit test using the project's existing test framework, matching its conventions.

- Skill: `jcaiagent7143-ui/add-unit-test` (Agent Skill)
- Install (CLI): `npx skillmds@latest add jcaiagent7143-ui/add-unit-test`
- Raw SKILL.md: https://api.skillmd.com/api/skills/jcaiagent7143-ui/add-unit-test/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: jcaiagent7143-ui (https://skillmd.com/u/jcaiagent7143-ui)
- Updated: 2026-09-10
- Page: https://skillmd.com/skills/jcaiagent7143-ui/add-unit-test

---


# Add unit test

## Steps

1. **Find an existing test** for a similar function. Match its style — class-based vs functional, parametrize vs loop, mocking style.
2. **Locate the test file**. Conventions vary: `tests/test_foo.py`, `test_foo.py` next to `foo.py`, or `src/foo/_test.py`. Don't invent a new one.
3. **Test the public behavior**, not implementation details. Edge cases first: empty input, boundary values, error paths.
4. **Avoid mocking yfinance / requests / DB clients** by isolating logic from I/O — pass dataframes/dicts to pure functions and let the network boundary live in one place.
5. **Run only the new test first** (`pytest -k test_<name>` or `python -m unittest test_module.TestClass.test_method`) to confirm it actually exercises the change.
6. **Then run the full suite** with `{{ profile.test_command if profile and profile.test_command else "the project test_command" }}`.

## Failure modes to avoid

- Adding pytest fixtures when the project uses plain unittest.
- Testing the test framework instead of the function ("assert test runner works").
- Mocking the world — if you're mocking 5 things to test one function, refactor.
- Writing tests that pass only with the implementation in front of you (write the test first if you can).

