testing-services

Write AAA-based unit tests for Python service classes with pytest and unittest.mock.

Updated Jan 25, 2026
One-click install
npx skills add https://github.com/gestrich/python-architecture --skill testing-services
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing-services
Source: https://github.com/gestrich/python-architecture/tree/main/plugin/skills/testing-services
Command: npx skills add https://github.com/gestrich/python-architecture --skill testing-services

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps teams reliably test Python service classes by enforcing Arrange-Act-Assert patterns, promoting clear separation between setup, action, and verification to improve test quality and maintainability.

Core Features & Use Cases

  • AAA testing pattern guidance: structure unit tests with Arrange, Act, and Assert sections for every service.
  • Boundary mocking discipline: instructs when and what to mock (external services, APIs, file I/O, databases) while keeping domain models intact.
  • Use Case: when refining test coverage for a service, generate focused tests that validate business rules and interactions with dependencies.

Quick Start

Tell me the service class name and dependencies, and I will generate AAA-based unit tests with appropriate mocks.

Frequently Asked Questions about testing-services

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write unit tests for Python service classes using the Arrange-Act-Assert pattern?

To write unit tests using the Arrange-Act-Assert pattern, structure your test code into three clear sections: set up the necessary preconditions and mocks, execute the service method, and verify the business rules and interactions with dependencies.

What should I mock when testing Python service-layer code?

When testing Python service-layer code, you should mock external boundaries like repositories, APIs, file I/O, and databases using unittest.mock, while keeping your internal domain models intact to validate actual business rules.

Can I use pytest to test interactions between my service and external APIs?

Yes, you can use pytest with unittest.mock to test interactions between your service and external APIs by mocking the API calls, allowing you to verify correct service behavior without requiring live network requests.

What is the best way to structure pytest tests for Python services?

The best way to structure pytest tests for Python services is to apply the Arrange-Act-Assert pattern, ensuring clear separation between test setup, action execution, and result verification to improve test quality and maintainability.

Does boundary mocking require unittest.mock for Python service testing?

Yes, boundary mocking for Python service testing requires the unittest.mock library to replace external dependencies like databases and APIs, ensuring your unit tests remain focused on service-layer behavior.

Why do my pytest unit tests fail when testing service-layer code with database calls?

Your pytest unit tests fail because they execute live database calls instead of mocking them; apply boundary mocking with unittest.mock to isolate the service and verify business rules without real I/O operations.