Added comprehensive documentation for the KMM project structure, build commands, and UI testing setup/troubleshooting. Documentation added: - CLAUDE.md: Complete KMM project guide for Claude Code with architecture, build commands, common tasks, and development patterns - iosApp/UI_TESTS_*.md: UI testing strategy, implementation guides, summaries - iosApp/XCUITEST_*.md: XCUITest implementation and debugging guides - iosApp/TEST_FAILURES_ANALYSIS.md: Analysis of common test failures - iosApp/ACCESSIBILITY_IDENTIFIERS_FIX.md: Guide for fixing accessibility issues - iosApp/FIX_TEST_TARGET*.md: Guides for fixing test target configuration - iosApp/fix_test_target.sh: Script to automate test target setup The CLAUDE.md serves as the primary documentation for working with this repository, providing quick access to build commands, architecture overview, and common development tasks for both iOS and Android platforms. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
4.6 KiB
Fix: Test Target Configuration
Problem
When compiling tests, you're seeing:
@testable import iosApp
No such module 'iosApp'
This means the test target (MyCribTests) is not properly configured to access the main app target (iosApp).
Solution: Configure Test Target in Xcode
Step 1: Open Xcode Project
cd /Users/treyt/Desktop/code/MyCrib/MyCribKMM/iosApp
open iosApp.xcodeproj
Step 2: Add Target Dependency
- Select the project in the Project Navigator (top item, blue icon)
- Select
MyCribTeststarget in the targets list (middle column) - Go to "Build Phases" tab (top of editor)
- Expand "Dependencies" section
- Click the "+" button under Dependencies
- Select
iosAppfrom the list - Click "Add"
Step 3: Configure Test Host
- Still in
MyCribTeststarget → Build Settings tab - Search for "Test Host"
- Set Test Host to:
$(BUILT_PRODUCTS_DIR)/iosApp.app/iosApp - Search for "Bundle Loader"
- Set Bundle Loader to:
$(TEST_HOST)
Step 4: Enable Testability
- Select
iosApptarget (main app) - Go to Build Settings tab
- Search for "Enable Testability"
- Set Enable Testability to YES for Debug configuration
- (Leave it NO for Release)
Step 5: Verify Module Name
- Select
iosApptarget - Go to Build Settings tab
- Search for "Product Module Name"
- Verify it says
iosApp- If it's different (e.g., "MyCrib"), you need to update your imports
Step 6: Clean and Build
- Product → Clean Build Folder (or press
⌘ + Shift + K) - Product → Build For → Testing (or press
⌘ + Shift + U)
Step 7: Verify Fix
Open any test file (e.g., ContractorViewModelTests.swift) and verify the import works:
@testable import iosApp // Should no longer show error
Alternative: Command Line Fix (Advanced)
If you prefer command-line configuration, you can use xcodebuild with PlistBuddy, but the Xcode GUI method above is safer and recommended.
Visual Guide
What It Should Look Like:
MyCribTests Target → Build Phases → Dependencies:
✅ iosApp (target)
MyCribTests Target → Build Settings:
Test Host: $(BUILT_PRODUCTS_DIR)/iosApp.app/iosApp
Bundle Loader: $(TEST_HOST)
iosApp Target → Build Settings:
Enable Testability: Yes (Debug only)
Product Module Name: iosApp
Common Issues & Solutions
Issue 1: Still getting "No such module"
Solution:
- Clean build folder (
⌘ + Shift + K) - Delete derived data:
rm -rf ~/Library/Developer/Xcode/DerivedData/iosApp-* - Restart Xcode
- Build again
Issue 2: Module name is different
Solution:
- Check what the actual module name is:
- Select
iosApptarget → Build Settings → Product Module Name
- Select
- Update all test imports to match:
@testable import <ActualModuleName>
Issue 3: "Target is not an application"
Solution:
- Make sure you selected the main app target (
iosApp), not the extension target - The Test Host should point to the
.appbundle
Issue 4: Xcode can't find the app
Solution:
- Build the main app first:
⌘ + B - Then build tests:
⌘ + Shift + U
Quick Verification Checklist
After making changes, verify:
MyCribTeststarget hasiosAppin Dependencies- Test Host is set to
$(BUILT_PRODUCTS_DIR)/iosApp.app/iosApp - Bundle Loader is set to
$(TEST_HOST) iosApptarget has "Enable Testability" = YES (Debug)- Product Module Name matches your import statement
- Project builds successfully (
⌘ + B) - Tests build successfully (
⌘ + Shift + U) - No import errors in test files
Why This Happens
The test target needs explicit configuration to:
- Know which app to test (Target Dependency)
- Where to find the app binary (Test Host)
- Access internal/private code (Enable Testability + @testable import)
Without these settings, the compiler doesn't know that iosApp module exists.
After Fixing
Once configured, your tests will:
- ✅ Import the main app module successfully
- ✅ Access internal classes and methods with
@testable import - ✅ Run against the actual app binary
- ✅ Have access to all app code for testing
Estimated Time: 2-3 minutes Difficulty: Easy (GUI-based) Risk: Low (non-destructive changes)
Last Updated: November 18, 2025 Issue: Test target not configured for app module access Resolution: Add target dependency and configure test host in Xcode