tdd-feature
Red-green-refactor scaffold for building new features with TDD. Write failing tests first, then implement to pass. Use when building new features test-first.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Red-green-refactor scaffold for building new features with TDD. Write failing tests first, then implement to pass. Use when building new features test-first.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Anicca earn skill (GATE-0). The automaton loop calls run.sh each wake to discover and execute an earn (x402 / 0xwork / litcoin / nookplot), then VERIFIES it on-chain (tx receipt 0x1 + USDC before/after delta) and appends one line to state/earn-ledger.jsonl. One profitable wake (net>0 AND status 0x1) is the real launch gate. Use when wiring earn into the agent loop, recording an earn outcome, or verifying a profitable wake.
Universal AI-powered web scraper for any platform. Scrape data from Instagram, Facebook, TikTok, YouTube, Google Maps, Google Search, Google Trends, Booking.com, and TripAdvisor. Use for lead generation, brand monitoring, competitor analysis, influencer discovery, trend research, content analytics, audience analysis, or any data extraction task.
Build and deploy production apps using AppFactory's 7 pipelines (websites, mobile, dApps, AI agents, plugins, mini apps, bots). One prompt → live URL.
iOS Simulator automation using AXe CLI for touch gestures, text input, hardware buttons, screenshots, video recording, and accessibility inspection. Use when automating iOS Simulator interactions, writing UI tests, capturing screenshots/video, or inspecting accessibility elements. Triggers on iOS Simulator automation, AXe CLI usage, simulator tap/swipe/gesture commands, or accessibility testing tasks.
Deep competitive analysis for iOS/macOS apps including feature comparison, pricing analysis, strengths/weaknesses, market positioning, and differentiation opportunities. Use when user asks for competitive analysis, competitor research, feature comparison, market positioning, or wants to understand competition in detail.
Configure notification integrations (Telegram, Discord, Slack) via natural language
| name | tdd-feature |
| description | Red-green-refactor scaffold for building new features with TDD. Write failing tests first, then implement to pass. Use when building new features test-first. |
| allowed-tools | ["Read","Write","Edit","Glob","Grep","Bash","AskUserQuestion"] |
Build new features using the red-green-refactor cycle. Tests define the spec, AI generates the implementation, tests verify correctness.
Use this skill when the user:
Source: Kent Beck - Canon TDD
1. Write a list of the test scenarios you want to cover
2. Turn exactly one item on the list into an actual, concrete, runnable test
3. Change the code to make the test (& all previous tests) pass
4. Optionally refactor to improve the implementation design
5. Until the list is empty, go back to #2
The test is your acceptance criteria in code form. AI excels at going from failing test to passing implementation — it's a concrete, unambiguous target.
Before writing any code or tests, understand:
Sketch the public interface before writing tests:
// Example: Designing a FavoriteManager
protocol FavoriteManaging {
func add(_ item: Item) async throws
func remove(_ item: Item) async throws
func isFavorite(_ item: Item) -> Bool
var favorites: [Item] { get }
var count: Int { get }
}
This doesn't need to compile yet — it's the contract you'll test against.
Write tests for each behavior. Start with the simplest case and build up.
import Testing
@testable import YourApp
@Suite("FavoriteManager")
struct FavoriteManagerTests {
// 1. Construction
@Test("starts with empty favorites")
func startsEmpty() {
let manager = FavoriteManager()
#expect(manager.favorites.isEmpty)
#expect(manager.count == 0)
}
// 2. Happy path
@Test("can add a favorite")
func addFavorite() async throws {
let manager = FavoriteManager()
let item = Item(id: "1", title: "Test")
try await manager.add(item)
#expect(manager.count == 1)
#expect(manager.isFavorite(item))
}
// 3. State verification
@Test("can remove a favorite")
func removeFavorite() async throws {
let manager = FavoriteManager()
let item = Item(id: "1", title: "Test")
try await manager.add(item)
try await manager.remove(item)
#expect(manager.count == 0)
#expect(!manager.isFavorite(item))
}
// 4. Edge cases
@Test("adding duplicate does not increase count")
func addDuplicate() async throws {
let manager = FavoriteManager()
let item = Item(id: "1", title: "Test")
try await manager.add(item)
try await manager.add(item)
#expect(manager.count == 1)
}
@Test("removing non-existent item does nothing")
func removeNonExistent() async throws {
let manager = FavoriteManager()
let item = Item(id: "1", title: "Test")
try await manager.remove(item)
#expect(manager.count == 0)
}
// 5. Error handling
@Test("throws when storage is full")
func storageFullError() async {
let manager = FavoriteManager(maxCapacity: 2)
let items = (1...3).map { Item(id: "\($0)", title: "Item \($0)") }
await #expect(throws: FavoriteError.capacityExceeded) {
for item in items {
try await manager.add(item)
}
}
}
// 6. Ordering
@Test("favorites are in insertion order")
func insertionOrder() async throws {
let manager = FavoriteManager()
let items = ["C", "A", "B"].map { Item(id: $0, title: $0) }
for item in items {
try await manager.add(item)
}
#expect(manager.favorites.map(\.title) == ["C", "A", "B"])
}
}
Run tests — they should ALL fail (the type doesn't even exist yet).
Now implement the feature. Pass the tests as context to AI:
Prompt to Claude: "Here are my failing tests for FavoriteManager.
Implement the FavoriteManager class to make all tests pass.
Follow the protocol FavoriteManaging."
fastlane test
With all tests green, clean up the implementation:
Run tests after every refactor step. If any test fails, you've changed behavior — revert.
Once the unit is solid, write integration tests:
@Suite("FavoriteManager Integration")
struct FavoriteManagerIntegrationTests {
@Test("persists favorites across sessions")
func persistence() async throws {
let store = InMemoryStore()
// Session 1: Add favorite
let manager1 = FavoriteManager(store: store)
try await manager1.add(Item(id: "1", title: "Test"))
// Session 2: Verify it persists
let manager2 = FavoriteManager(store: store)
await manager2.loadFavorites()
#expect(manager2.count == 1)
}
}
RED → Write one failing test (30 seconds - 2 minutes)
GREEN → Make it pass with simplest code (1 - 5 minutes)
REFACTOR → Clean up while tests stay green (1 - 3 minutes)
REPEAT → Next test
Cadence matters. If you're spending more than 5 minutes on GREEN, the test might be too big. Break it into smaller tests.
@Suite("SearchViewModel")
struct SearchViewModelTests {
@Test("starts in idle state")
@Test("searching updates state to loading")
@Test("successful search shows results")
@Test("empty search shows empty state")
@Test("failed search shows error")
@Test("debounces rapid input")
@Test("cancels previous search on new input")
}
@Suite("ItemRepository")
struct ItemRepositoryTests {
@Test("fetches items from remote")
@Test("caches fetched items locally")
@Test("returns cached items when offline")
@Test("syncs local changes to remote")
@Test("handles conflict resolution")
@Test("deletes expire cached items")
}
@Suite("SubscriptionManager")
struct SubscriptionManagerTests {
@Test("free user has basic access")
@Test("pro user has full access")
@Test("expired subscription reverts to free")
@Test("family member inherits subscription")
@Test("trial period grants pro access")
@Test("grace period maintains access after lapse")
}
## TDD Feature: [Feature Name]
### API Design
```swift
// Protocol / public interface
startsEmpty — Initial stateaddFavorite — Happy pathremoveFavorite — State changeaddDuplicate — Edge caseremoveNonExistent — Edge casestorageFullError — Error handlingFile: Sources/Features/FavoriteManager.swift
All [X] tests passing.
## Common Pitfalls
| Pitfall | Problem | Solution |
|---------|---------|----------|
| Writing too many tests before implementing | Overwhelming; can't see progress | Write 2-3 tests, implement, repeat |
| Tests that test implementation | Brittle; break on refactor | Test behavior and outcomes only |
| Skipping the refactor step | Accumulating technical debt | Refactor every 3-5 green cycles |
| AI implementing beyond the tests | Untested code in production | Only implement what tests require |
| Not running tests after each change | Silent regressions | `fastlane test` after every edit |
## iOS TDD Patterns
### xcconfig Template Pattern
Secrets (API keys) must never be hardcoded. Use xcconfig:
REVENUECAT_API_KEY = YOUR_KEY_HERE
REVENUECAT_API_KEY = appl_OnzEebYgDRvF...
Add to Info.plist: `RevenueCatAPIKey = $(REVENUECAT_API_KEY)`
Test: verify config reads from Info.plist, not hardcoded string.
### Protocol-Based Dependency Injection
Every service that talks to external systems must have a protocol:
```swift
protocol SubscriptionServiceProtocol {
func purchase(package: Package) async throws -> Bool
func restorePurchases() async throws
var isSubscribed: Bool { get }
}
// Production
class SubscriptionService: SubscriptionServiceProtocol { ... }
// Test
class MockSubscriptionService: SubscriptionServiceProtocol {
var purchaseResult: Bool = true
func purchase(package: Package) async throws -> Bool { purchaseResult }
...
}
# Fastfile lanes
lane :test do
run_tests(scheme: APP_SCHEME, device: DEVICE)
end
lane :build do
build_app(scheme: APP_SCHEME, export_method: "app-store")
end
lane :build_for_simulator do
build_app(scheme: APP_SCHEME, configuration: "Debug",
destination: "generic/platform=iOS Simulator")
end
Always use fastlane test / fastlane build. Never xcodebuild directly.
@Test("validates all pain areas", arguments: PainArea.allCases)
func validatePainArea(area: PainArea) {
#expect(!area.rawValue.isEmpty)
#expect(area.displayName.count > 0)
}
1. Models (pure data, no dependencies)
2. Services (protocol + implementation, mock dependencies)
3. ViewModels (depend on service protocols, inject mocks)
4. Integration (real services, in-memory storage)
80%+ line coverage. Check with: fastlane test + Xcode coverage report.
testing/test-contract/ — for protocol-level test suitestesting/test-data-factory/ — for reducing test setup boilerplate