AGENT SKILL

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 test reports fewer suites than test files exist (stale generate)
  • @testable import fails 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 test after adding test files — sources are globbed at generate time; stale projects skip new files and the suite count won't grow (you'll see TEST SUCCEEDED running 0 tests).
  • Use import Testing + #expect (Swift Testing) for unit tests; XCUITest still requires import XCTest.
  • @MainActor struct MyTests works fine under Swift Testing when the app target defaults to MainActor isolation.
  • UI tests: override @AppStorage per-launch without touching persisted defaults via the NSArgumentDomain — app.launchArguments = ["-hasSeenOnboarding", "YES"]; UserDefaults reads the argument domain first.
  • SwiftUI List rows render as staticTexts, not buttons, and bottom sections need app.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 — the SWIFT_DEFAULT_ACTOR_ISOLATION errors behind the matching-isolation setting above.
  • xcode-cloud-post-clone-contract — Xcode Cloud's clean clone needs xcodegen generate in ci_post_clone.sh before any build or test.

04 同仓库更多 Skills

abhijitbansal
abhijitbansal/claude-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".

★ 1
abhijitbansal
abhijitbansal/claude-skills

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.

★ 1
abhijitbansal
abhijitbansal/claude-skills

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.

★ 1
abhijitbansal
abhijitbansal/claude-skills

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

★ 1
abhijitbansal
abhijitbansal/claude-skills

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

★ 1
abhijitbansal
abhijitbansal/claude-skills

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.

★ 1