# Write Unit Tests

> Generate unit tests for a selected function, model, or viewmodel using the project's test framework. Use when this capability is needed.

- Skill: `tomevault-io/write-unit-tests-3` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/write-unit-tests-3`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/write-unit-tests-3/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/write-unit-tests-3

---


Steps:

1. Identify the function, model, or class to be tested.
2. Use the test framework configured in the project (e.g., XCTest for iOS).
3. Create a corresponding test file if it doesn't exist:
   - e.g., `Tests/ModelNameTests.swift` or `Tests/ViewModelTests.swift`
4. Write tests that:
   - Cover expected input/output
   - Handle edge cases and invalid inputs
   - Assert side effects if relevant
5. Ask:
   > "Should I include test cases for error handling or performance?"

Example (Swift/XCTest):

```swift
func testWorkoutInitialization() {
    let workout = Workout(date: Date())
    XCTAssertEqual(workout.sets.count, 0)
}
```

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/mdeforest) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-16 -->

