iktakahiro/python-fastapi-ddd-skill · Archived

python-fastapi-ddd-testing-skill

Guides unit testing for Python DDD + Onion Architecture apps (Domain Entities/Value Objects and UseCases) using pytest and repository mocks, based on the dddpy reference. Use when adding tests, choosing what to mock, or structuring test folders for a DDD FastAPI project.

First seen Feb 13, 2026

Installation

$ npx skills add iktakahiro/python-fastapi-ddd-skill --skill python-fastapi-ddd-testing-skill

Stronger alternatives

This repository is archived — consider an actively maintained alternative.

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from iktakahiro/python-fastapi-ddd-skill.

npx skills add iktakahiro/python-fastapi-ddd-skill

Browse all from iktakahiro/python-fastapi-ddd-skill

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Repository health

Stars 4
License Apache-2.0
Default branch main
Open issues 0
Status Archived

Skill metadata

Parsed from SKILL.md frontmatter.

Version1.0.0
LicenseApache-2.0
More metadata
author
Takahiro Ikeuchi
version
1.0.0

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 1,946 B
  • docs SUMMARY.md 311 B

History

  1. First seen on skills.sh
  2. First recorded snapshot · 22 installs

SKILL.md

Testing 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)

  1. Domain tests: no mocks, assert invariants and state transitions.
  2. UseCase tests: mock repository interfaces (Mock(spec=...)), assert:

- correct repository method calls - correct domain exceptions raised - correct entity state transitions

  1. 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.