xcodegen-test-targets
Adding Swift Testing unit tests and XCUITest targets to an XcodeGen (project.yml) iOS app that has none. Covers the exact TEST_HOST / BUNDLE_LOADER shape for hosted unit tests, wiring the scheme's test action (tests silently don't run if the target isn't listed), regenerating before every xcodebuild test (sources are globbed at generate time), matching SWIFT_DEFAULT_ACTOR_ISOLATION so @testable import doesn't break, and overriding @AppStorage per-launch via NSArgumentDomain in UI tests. Trigger on "add tests" to an XcodeGen iOS app, or when xcodebuild test reports fewer suites than test files exist.
- License 许可
- MIT
- 最近更新
- 2026-11-07
- Stars
- ★ 1
- Forks
- 1
01 前言 Front Matter
- name
- xcodegen-test-targets
- description
- Adding Swift Testing unit tests and XCUITest targets to an XcodeGen (project.yml) iOS app that has none. Covers the exact TEST_HOST / BUNDLE_LOADER shape for hosted unit tests, wiring the scheme's test action (tests silently don't run if the target isn't listed), regenerating before every xcodebuild test (sources are globbed at generate time), matching SWIFT_DEFAULT_ACTOR_ISOLATION so @testable import doesn't break, and overriding @AppStorage per-launch via NSArgumentDomain in UI tests. Trigger on "add tests" to an XcodeGen iOS app, or when xcodebuild test reports fewer suites than test files exist.
03 SKILL.md 正文
Adding Test Targets to an XcodeGen (project.yml) iOS Project
Why this skill exists
XcodeGen ships no test-target template. Hosted unit tests fail to link or run
without the exact TEST_HOST / BUNDLE_LOADER shape; tests silently don't run
if the scheme's test action omits the target; and freshly created test files
aren't compiled until the project is regenerated (so the suite count quietly
fails to grow).
When to use
- "Add tests" to any XcodeGen-managed iOS app
xcodebuild testreports fewer suites than test files exist (stale generate)@testable importfails with actor-isolation errors in a fresh test target
Unit test target (Swift Testing, hosted in the app)
AppTests:
type: bundle.unit-test
platform: iOS
sources: [AppTests]
dependencies:
- target: App
settings:
base:
BUNDLE_LOADER: "$(TEST_HOST)"
TEST_HOST: "$(BUILT_PRODUCTS_DIR)/App.app/App" # .app/<executable>, iOS shape
GENERATE_INFOPLIST_FILE: YES
# Match the app target's isolation or @testable import breaks:
SWIFT_DEFAULT_ACTOR_ISOLATION: MainActor
SWIFT_APPROACHABLE_CONCURRENCY: YES
UI test target
type: bundle.ui-testing, a dependency on the app target, and
TEST_TARGET_NAME: App (no TEST_HOST).
Scheme — tests DO NOT run unless listed
schemes:
App:
test:
config: Debug
targets: [AppTests, AppUITests]
Run:
xcodegen generate && \
xcodebuild test -project App.xcodeproj -scheme App \
-destination 'platform=iOS Simulator,name=<installed iPhone sim>'
Look up an installed simulator name with xcrun simctl list devices available.
Traps
- Regenerate before every
xcodebuild testafter adding test files — sources are globbed at generate time; stale projects skip new files and the suite count won't grow (you'll seeTEST SUCCEEDEDrunning 0 tests). - Use
import Testing+#expect(Swift Testing) for unit tests; XCUITest still requiresimport XCTest. @MainActor struct MyTestsworks fine under Swift Testing when the app target defaults to MainActor isolation.- UI tests: override
@AppStorageper-launch without touching persisted defaults via the NSArgumentDomain —app.launchArguments = ["-hasSeenOnboarding", "YES"];UserDefaultsreads the argument domain first. - SwiftUI
Listrows render asstaticTexts, notbuttons, and bottom sections needapp.swipeUp()before querying.
Related skills
swiftdata-inmemory-test-harness— in-memory SwiftData containers for the unit tests this skill sets up.swift6-mainactor-compile-fixes— theSWIFT_DEFAULT_ACTOR_ISOLATIONerrors behind the matching-isolation setting above.xcode-cloud-post-clone-contract— Xcode Cloud's clean clone needsxcodegen generateinci_post_clone.shbefore any build or test.
04 同仓库更多 Skills
second-wind
Orchestrate long unattended Claude Code runs across multiple repos with the wind CLI. Use when the user wants to run Claude Code overnight, resume sessions after the 5-hour usage limit, run Claude in many repos at once via tmux, or says "set up second wind", "wind up", "overnight run", "resume after limit", "usage limit orchestrator".
structured-output-adaptive-thinking-token-bloat
A Claude API call using output_config.format (json_schema structured outputs) with thinking:{type:"adaptive"} burns most of its output budget on thinking (observed ~21k of ~24k tokens) without improving JSON quality, making the run up to ~5x more expensive than the same call with thinking omitted — use when calling the Messages API with a json_schema output format for extraction, ranking, classification, or summarization tasks, or when a schema-constrained call's usage.output_tokens is far larger than the returned JSON.
review
Apply a code-review lens to a diff, branch, or file — find correctness bugs, security issues, and quality problems, ranked by severity, with a concrete fix for each. Use when the user says "review this", "review my diff", "check this PR", "look this over before I commit", or "is this safe". Skip when the user wants the code written, not reviewed.
refresh
Rebuild the prompt-craft command registry and usage profile, and print a summary of installed commands and your personalized recommendations. Use when you install or update plugins and want the advisor to pick them up immediately, or say "refresh prompt-craft", "rebuild the command registry".
refactor
Apply a refactoring lens — restructure code without changing behavior, guarded by tests that pass before and after. Use when the user says "refactor", "clean this up", "extract this", "simplify this", "reduce duplication", or "make this readable" on existing working code. Skip when the change is meant to alter behavior (that's a feature or a fix).
plan
Decompose a non-trivial task into an explicit, tracked plan with goals and per-step acceptance criteria before writing code. Use when the user says "plan this", "break this down", "what's the plan", or asks for a multi-step feature/refactor that touches more than one file. Pairs with plan mode. Skip for single-edit changes that need no decomposition.