Kingfisher's test suite is located in the Tests/KingfisherTests/ directory and provides comprehensive coverage for all major components of the library. The test suite uses XCTest framework with custom helper utilities and the Nocilla dependency for HTTP request stubbing.
Tests/Dependency/Nocilla/)Tests/KingfisherTests/KingfisherTestHelper.swiftTests/KingfisherTests/Utils/StubHelpers.swiftTests/KingfisherTests/dancing-banana.gif - Animated GIF for testingTests/KingfisherTests/single-frame.gif - Single frame GIF for testingCache Layer Tests
Tests/KingfisherTests/ImageCacheTests.swift - Tests for the main ImageCache functionalityTests/KingfisherTests/MemoryStorageTests.swift - Memory cache specific testsTests/KingfisherTests/DiskStorageTests.swift - Disk storage specific testsTests/KingfisherTests/StorageExpirationTests.swift - Cache expiration policy testsNetworking Tests
Tests/KingfisherTests/ImageDownloaderTests.swift - Image downloading and session managementTests/KingfisherTests/ImagePrefetcherTests.swift - Batch image prefetching functionalityTests/KingfisherTests/DataReceivingSideEffectTests.swift - Data processing side effectsManager Tests
Tests/KingfisherTests/KingfisherManagerTests.swift - Central coordinator testsTests/KingfisherTests/KingfisherOptionsInfoTests.swift - Configuration options testsTests/KingfisherTests/ImageProcessorTests.swift - Image transformation pipeline testsTests/KingfisherTests/ImageDrawingTests.swift - Image drawing and rendering testsTests/KingfisherTests/ImageExtensionTests.swift - Core image extensions testsTests/KingfisherTests/ImageModifierTests.swift - Request modifier testsUIKit Tests
Tests/KingfisherTests/ImageViewExtensionTests.swift - UIImageView extension testsTests/KingfisherTests/UIButtonExtensionTests.swift - UIButton extension testsAppKit Tests
Tests/KingfisherTests/NSButtonExtensionTests.swift - NSButton extension tests (macOS)Tests/KingfisherTests/LivePhotoSourceTests.swift - Live Photo support testsTests/KingfisherTests/ImageDataProviderTests.swift - Custom data provider testsTests/KingfisherTests/RetryStrategyTests.swift - Network retry strategy testsTests/KingfisherTests/StringExtensionTests.swift - String utility extension tests# Install dependencies first
bundle install
# Run all tests across all platforms
bundle exec fastlane tests
# Expected output:
# [08:30:00]: ------------------------------
# [08:30:00]: --- Step: default_platform ---
# [08:30:00]: ------------------------------
# [08:30:00]: Driving the lane 'ios tests' 🚀
# [08:30:01]: ------------------
# [08:30:01]: --- Step: scan ---
# [08:30:01]: ------------------
# [08:30:01]: Running Tests: ▸ Touching Kingfisher.framework
# [08:30:45]: Test Succeeded
# Run tests for specific platform
bundle exec fastlane test destination:"platform=iOS Simulator,name=iPhone 15"
bundle exec fastlane test destination:"platform=macOS"
bundle exec fastlane test destination:"platform=tvOS Simulator,name=Apple TV"
# CI-specific test command (used in continuous integration)
DESTINATION="platform=iOS Simulator,name=iPhone 15,OS=17.5" bundle exec fastlane test_ci
# Build only (for watchOS where full testing isn't supported)
bundle exec fastlane build destination:"platform=watchOS Simulator,name=Apple Watch Series 9 (41mm)"
# Open workspace in Xcode
open Kingfisher.xcworkspace
# Then use Xcode's test navigator or press Cmd+U to run all tests
# Or use xcodebuild directly:
xcodebuild test -workspace Kingfisher.xcworkspace -scheme Kingfisher -destination "platform=iOS Simulator,name=iPhone 15"
Tests/
├── Dependency/
│ └── Nocilla/ # HTTP stubbing framework
│ ├── LICENSE
│ ├── README.md
│ └── Nocilla/ # Nocilla source files
│ ├── Categories/ # NSData and NSString extensions
│ ├── DSL/ # Domain-specific language for stubbing
│ ├── Diff/ # Request diff utilities
│ ├── Hooks/ # HTTP client hooks (NSURLSession, etc.)
│ ├── Matchers/ # Request matching logic
│ ├── Model/ # HTTP request/response models
│ └── Stubs/ # Stub implementation
└── KingfisherTests/
├── Info.plist
├── KingfisherTestHelper.swift # Main test helper utilities
├── KingfisherTests-Bridging-Header.h # Objective-C bridging
├── Utils/
│ └── StubHelpers.swift # Network stubbing helpers
├── dancing-banana.gif # Animated test image
├── single-frame.gif # Static test image
└── *Tests.swift # Individual test files
Xcode Scheme: Kingfisher.xcscheme
Fastlane Configuration: fastlane/Fastfile
tests lane: Runs tests on all platformstest_ci lane: CI-specific testing with environment-based destinationtest lane: Core test execution with scan actionbuild lane: Build-only verification (used for watchOS)Platform Test Destinations:
platform=iOS Simulator,name=iPhone 15,OS=17.5platform=macOSplatform=tvOS Simulator,name=Apple TV,OS=17.5platform=watchOS Simulator,name=Apple Watch Series 9 (41mm),OS=10.5 (build only)The KingfisherTestHelper.swift provides:
cleanDefaultCache, clearCaches)renderEqual)delay)The StubHelpers.swift provides:
stub() - Create HTTP response stubs with custom data and headersdelayedStub() - Create delayed response stubs for timing tests