Unit Testing Framework

Unit Testing Framework

Guides an AI agent to write fast, isolated unit tests using the Arrange-Act-Assert pattern, mocks and edge cases across Jest, pytest, JUnit and RSpec.

Skill files9 files

references/

scripts/

templates/

SKILL.md106 lines
1
---
2
name: unit-testing-framework
3
description: >
4
Write comprehensive unit tests with high coverage using testing frameworks
5
like Jest, pytest, JUnit, or RSpec. Use when writing tests for functions,
6
classes, components, or establishing testing standards.
7
---
8
9
# Unit Testing Framework
10
11
## Table of Contents
12
13
- [Overview](#overview)
14
- [When to Use](#when-to-use)
15
- [Quick Start](#quick-start)
16
- [Reference Guides](#reference-guides)
17
- [Best Practices](#best-practices)
18
19
## Overview
20
21
Write effective unit tests that are fast, isolated, readable, and maintainable following industry best practices and AAA (Arrange-Act-Assert) pattern.
22
23
## When to Use
24
25
- Writing tests for new code
26
- Improving test coverage
27
- Establishing testing standards
28
- Refactoring with test safety
29
- Implementing TDD (Test-Driven Development)
30
- Creating test utilities and mocks
31
32
## Quick Start
33
34
Minimal working example:
35
36
```javascript
37
// Jest/JavaScript example
38
describe("UserService", () => {
39
describe("createUser", () => {
40
it("should create user with valid data", async () => {
41
// Arrange - Set up test data and dependencies
42
const userData = {
43
email: "john@example.com",
44
firstName: "John",
45
lastName: "Doe",
46
};
47
const mockDatabase = createMockDatabase();
48
const service = new UserService(mockDatabase);
49
50
// Act - Execute the function being tested
51
const result = await service.createUser(userData);
52
53
// Assert - Verify the outcome
54
expect(result.id).toBeDefined();
55
expect(result.email).toBe("john@example.com");
56
expect(mockDatabase.save).toHaveBeenCalledWith(
57
expect.objectContaining(userData),
58
);
59
});
60
});
61
});
62
```
63
64
## Reference Guides
65
66
Detailed implementations in the `references/` directory:
67
68
| Guide | Contents |
69
|---|---|
70
| [Test Structure (AAA Pattern)](references/test-structure-aaa-pattern.md) | Test Structure (AAA Pattern) |
71
| [Test Cases by Language](references/test-cases-by-language.md) | Test Cases by Language |
72
| [Mocking & Test Doubles](references/mocking-test-doubles.md) | Mocking & Test Doubles |
73
| [Testing Async Code](references/testing-async-code.md) | Testing Async Code, Test Coverage |
74
| [Testing Edge Cases](references/testing-edge-cases.md) | Testing Edge Cases |
75
| [Example: Complete Test Suite](references/example-complete-test-suite.md) | import { UserService } from "./user-service"; |
76
77
## Best Practices
78
79
### ✅ DO
80
81
- Write tests before or alongside code (TDD)
82
- Test one thing per test
83
- Use descriptive test names
84
- Follow AAA pattern
85
- Test edge cases and error conditions
86
- Keep tests isolated and independent
87
- Use setup/teardown appropriately
88
- Mock external dependencies
89
- Aim for high coverage on critical paths
90
- Make tests fast (< 10ms each)
91
- Use parameterized tests for similar cases
92
- Test public interfaces, not implementation
93
94
### ❌ DON'T
95
96
- Test implementation details
97
- Write tests that depend on each other
98
- Ignore failing tests
99
- Test third-party library code
100
- Use real databases/APIs in unit tests
101
- Make tests too complex
102
- Skip edge cases
103
- Forget to clean up resources
104
- Test everything (focus on business logic)
105
- Write flaky tests
106

© AJ Geddes · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…