django-outside-in-tdd
Drive Django features with outside-in and double-loop TDD: user story, Selenium or functional test, focused Django unit/integration tests, minimal i…
它会碰到什么
这一栏是扫描器报的事实,不是结论。命中多不等于有毒(安全工具、规则库、示例脚本本来就会包含危险写法),命中少也不等于干净。它和你手上的凭据、文件、网络有什么关系,需要你自己看。
技能内容
Django Outside-In TDD
Use this skill when a Django feature should be grown from observable user behavior down into views, forms, models, and helpers. Keep the outer test broad enough to prove user value and the inner tests small enough to keep the red/green loop fast.
Source Traceability
Primary source: Harry Percival, Test-Driven Development with Python, 3rd ed. Guidance is transformed and paraphrased from chapters 1-7, chapter 24, and Appendix A, especially the user-story-to-functional-test flow, double-loop TDD, working-state-to-working-state refactoring, and outside-in development.
Workflow
- Start from the user-visible behavior.
- Write a short user story or acceptance note.
- Choose one functional test only when the behavior crosses browser, routing, template, persistence, or integration boundaries.
- Run the outer test and make the failure useful.
- Confirm the failure is expected and points to the next missing behavior.
- Improve failure messages before implementation if the failure is vague.
- Drop into the inner loop.
- Add the smallest Django test for the next missing component: URL, view, template context, form, model, or helper.
- Use Django's test client,
RequestFactory, form instances, or model tests at the narrowest useful boundary.
- Make the inner test pass with minimal code.
- Avoid speculative data models, URLs, fields, and abstractions.
- Keep a scratchpad of next ideas instead of implementing them early.
- Refactor only on green.
- Refactor production code first, then test code.
- Preserve behavior through the existing tests.
- Return to the outer test to choose the next slice.
Read [patterns.md](references/patterns.md) for layer choices, refactoring rules, and failure-handling patterns.
Layer Choice
| Signal | Next Test |
| --- | --- |
| User workflow not proven | Functional test |
| URL or redirect missing | URL/view test |
| Template output changed | View/template integration test or HTML parser assertion |
| Validation rule unclear | Form or model test |
| Domain helper emerging | Plain Python unit test |
| Refactor crosses wiring | One integration test plus focused unit tests |
Guardrails
- Do not write production code before a failing proof unless the task is pure cleanup.
- Do not keep adding Selenium coverage for every branch; promote detailed cases to faster tests.
- Do not test constants or implementation details unless they are the public contract.
- Prefer working state to working state over large rewrites.
- Use existing green tests as a refactoring safety net before changing structure.
Verification
Before finishing, report:
- Outer behavior covered or intentionally not needed.
- Inner tests added, updated, or reused.
- Red failure or characterization observed before implementation when behavior changed.
- Focused Django test command and result.
- Any deliberate no-test exception with replacement verification.
想直接用这个技能?
本站把开放许可(MIT / Apache 等)的技能按仓库打包整理到网盘,点一下转存到你自己的网盘,不用一个个从 GitHub 拉。许可未声明的技能只给原始仓库链接,不打包。
它属于哪个仓库
plugins/LVTD-LLC/skills/skills/django-outside-in-tdd/SKILL.md