python-fastapi-ddd-testing-skill skill
Guides unit testing for Python applications using Domain-Driven Design and Onion Architecture with pytest and repository mocks.
- GitHub stars
- 5
- Files
- 3
- Last commit
- Oct 24, 2026
- License
- Apache-2.0
- Allowed tools
- —
What does the python-fastapi-ddd-testing-skill skill do?
python-fastapi-ddd-testing-skill guides unit testing for Python applications using Domain-Driven Design and Onion Architecture with pytest and repository mocks.
Summary generated from the skill's SKILL.md.
About the python-fastapi-ddd-testing-skill skill
Developers building Python applications with Domain-Driven Design and Onion Architecture can use this skill to implement structured unit testing. It provides guidance on testing the inner layers of an application, specifically focusing on Domain entities, Value Objects, and UseCase workflows. An agent should load this skill when a developer needs to write tests for business rules, determine which components require mocking, or organize a test directory to mirror the application layers.
The skill emphasizes a specific testing strategy where domain tests remain pure without mocks to validate invariants, while UseCase tests utilize unittest.mock.Mock with a repository interface specification to ensure correct method calls and state transitions. It produces structured testing patterns and folder hierarchies that follow the dddpy reference. By using pytest and repository mocks, it helps ensure that application logic is verified without the overhead of full HTTP or API integration tests.
What an agent can do with it
- 1Organizing test directory structuresA developer can ask for a folder layout that mirrors the Onion Architecture layers for a DDD project.
Written from the skill's SKILL.md. Every use case is checked against a quote from it.
How to install the python-fastapi-ddd-testing-skill skill
Each command copies the skill folder into the client's skills directory. Restart the client or start a new session to load it.Install the python-fastapi-ddd-testing-skill skill in Plugin
/plugin marketplace add iktakahiro/python-fastapi-ddd-skill /plugin install python-fastapi-ddd@python-fastapi-ddd-skills
Install the python-fastapi-ddd-testing-skill skill in Claude Code
~/.claude/skills/python-fastapi-ddd-testing-skill/SKILL.md
$ npx degit iktakahiro/python-fastapi-ddd-skill/skills/python-fastapi-ddd-testing-skill ~/.claude/skills/python-fastapi-ddd-testing-skillInstall the python-fastapi-ddd-testing-skill skill in Claude Code (project)
.claude/skills/python-fastapi-ddd-testing-skill/SKILL.md
$ npx degit iktakahiro/python-fastapi-ddd-skill/skills/python-fastapi-ddd-testing-skill .claude/skills/python-fastapi-ddd-testing-skillInstall the python-fastapi-ddd-testing-skill skill in Codex
~/.agents/skills/python-fastapi-ddd-testing-skill/SKILL.md
$ npx degit iktakahiro/python-fastapi-ddd-skill/skills/python-fastapi-ddd-testing-skill ~/.agents/skills/python-fastapi-ddd-testing-skillInstall the python-fastapi-ddd-testing-skill skill in Gemini CLI
~/.gemini/skills/python-fastapi-ddd-testing-skill/SKILL.md
$ npx degit iktakahiro/python-fastapi-ddd-skill/skills/python-fastapi-ddd-testing-skill ~/.gemini/skills/python-fastapi-ddd-testing-skillInstall the python-fastapi-ddd-testing-skill skill in Claude.ai
npx degit iktakahiro/python-fastapi-ddd-skill/skills/python-fastapi-ddd-testing-skill python-fastapi-ddd-testing-skill && zip -r python-fastapi-ddd-testing-skill.zip python-fastapi-ddd-testing-skill # claude.ai → Customize → Skills → + → Create skill → Upload a skill → python-fastapi-ddd-testing-skill.zip
SKILL.md
View on GitHubTesting DDD Layers with pytest (Domain / UseCase)
This skill focuses on unit tests for the inner layers:
- Domain: Value Objects + Entities (pure business rules)
- UseCase: application workflows that orchestrate Domain + Repository interfaces
It intentionally avoids full HTTP/API tests unless explicitly requested.
Test strategy (recommended)
- Domain tests: no mocks, assert invariants and state transitions.
- UseCase tests: mock repository interfaces (
Mock(spec=...)), assert:- correct repository method calls
- correct domain exceptions raised
- correct entity state transitions
- Infrastructure/Presentation: add integration tests separately (optional).
Folder structure
Mirror the Onion layers:
tests/
domain/{aggregate}/...
usecase/{aggregate}/...
infrastructure/... # optional integration tests
presentation/... # optional API tests
UseCase testing pattern (dddpy-based)
Use unittest.mock.Mock(spec=RepoInterface) so typos fail fast.
from unittest.mock import Mock
import pytest
@pytest.fixture
def todo_repository_mock():
return Mock(spec=TodoRepository)
def test_create_todo_calls_save(todo_repository_mock):
usecase = CreateTodoUseCaseImpl(todo_repository_mock)
title = TodoTitle("Test")
todo = usecase.execute(title=title)
todo_repository_mock.save.assert_called_once_with(todo)
For more examples (Value Object validation, entity lifecycle tests, and exception cases), read references/TESTING.md.
Files in this skill
3python-fastapi-ddd-testing-skill skill questions
How do I install the python-fastapi-ddd-testing-skill skill in Claude Code?
Run npx degit iktakahiro/python-fastapi-ddd-skill/skills/python-fastapi-ddd-testing-skill ~/.claude/skills/python-fastapi-ddd-testing-skill. Claude Code loads skills from ~/.claude/skills (all projects) or .claude/skills (one project) and uses a skill when its description matches the task.
Which clients can use the python-fastapi-ddd-testing-skill skill?
Any client that reads the Agent Skills format: Claude Code, Codex, Gemini CLI and claude.ai (upload as a ZIP). Scripts in the skill run only where the client allows code execution.
How should I structure my test folders for a DDD project?
You should mirror your Onion layers by creating separate directories for domain, usecase, infrastructure, and presentation tests.
How should I mock repositories in UseCase tests?
Use unittest.mock.Mock with the spec of the repository interface to ensure that typos cause failures.