Agent skill
test-service
Guide for testing service layer. Use when asked to test services. Directs to implementation-specific testing skills.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/test-service-madooei-backend-template-22d9c212
SKILL.md
Test Service
Service Types Have Different Testing Strategies
Services fall into two categories with different testing approaches:
| Type | Testing Strategy | Skill |
|---|---|---|
| Resource Service | Mock repository, test authorization + events | test-resource-service |
| Utility Service | Mock external APIs (fetch), test error handling | test-utility-service |
When to Test
Test services after you have:
- Created the service (
create-resource-serviceorcreate-utility-service) - Created any dependencies (repositories, schemas)
Which Skill to Use
Use test-resource-service when:
- Testing services that extend
BaseService - Testing CRUD operations on domain entities
- Testing authorization logic (admin vs owner vs other)
- Testing event emission
Examples: NoteService, UserService, CourseService
Use test-utility-service when:
- Testing services that call external APIs
- Testing authentication/authorization logic services
- Testing error handling for external failures
- Mocking
fetchor other network calls
Examples: AuthenticationService, AuthorizationService, EmailService
Common Testing Patterns
Both service types share these patterns:
User Context Fixtures
const adminUser: AuthenticatedUserContextType = {
userId: "admin-1",
globalRole: "admin",
};
const regularUser: AuthenticatedUserContextType = {
userId: "user-1",
globalRole: "user",
};
const otherUser: AuthenticatedUserContextType = {
userId: "user-2",
globalRole: "user",
};
Error Assertions
// Expect specific error type
await expect(service.someMethod()).rejects.toThrow(UnauthorizedError);
// Expect any error
await expect(service.someMethod()).rejects.toThrow();
Cleanup in beforeEach/afterEach
beforeEach(() => {
// Reset state
});
afterEach(() => {
vi.restoreAllMocks();
});
See Also
test-resource-service- Testing resource services (CRUD + events)test-utility-service- Testing utility services (external APIs)
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?