Generate comprehensive unit tests for iOS RxSwift project files (ViewModels, UseCases, Services). Creates complete test files with nested mocks, RxTest patterns, session error handling, and memory leak tests. Use when "generate unit tests", "write tests for", "create unit tests", "add tests for", or analyzing Swift files in PayooMerchant project.
/plugin marketplace add daispacy/py-claude-marketplace/plugin install py-plugin@py-claude-marketplaceThis skill is limited to using the following tools:
examples.mdtemplates.mdAutomatically generate comprehensive unit tests for iOS RxSwift project following Clean Architecture patterns.
Ask user for file to test (if not provided):
Which file would you like to generate tests for?
Provide the file path or class name (e.g., BalanceInformationViewModel.swift)
Read target file and determine type:
ViewModelType, Input, Output, transform method*UseCaseType protocolCRITICAL: Read the comprehensive testing guide:
~/Library/Application Support/Code/User/prompts/ios-mc-generate-unit-test.prompt.md
This guide contains ALL rules, patterns, and examples to follow.
Extract from target file:
Search for protocol definitions if needed:
Glob: **/*UseCaseType.swift
Grep: "protocol [DependencyName]"
Create complete test file at:
PayooMerchantTests/[appropriate-folder]/[ClassName]Tests.swift
Folder structure:
PayooMerchantTests/ViewModel/PayooMerchantTests/UseCase/PayooMerchantTests/Mock/Service/Test file MUST include:
Required imports:
import XCTest
import RxSwift
import RxCocoa
import RxTest
import RxBlocking
import Domain
@testable import PayooMerchant
Test class with nested mocks:
private final class nested inside test classcallCount, lastParams)Properties section:
private var disposeBag: DisposeBag!private var scheduler: TestScheduler!setUp/tearDown:
Test data factories:
Comprehensive test methods:
Follow naming convention:
func test_methodName_condition_expectedBehavior()
TestScheduler and hot observables for inputsfunc test_viewModel_shouldDeallocateProperly()
func test_catchSessionError_SessionTimeoutError_shouldSetExpiredState()
func test_catchSessionError_ForceUpdateError_shouldSetForceUpdateState()
Ensure:
private final classAfter generating tests, show:
✅ Generated Unit Tests: [ClassName]Tests.swift
📁 Location: PayooMerchantTests/[folder]/[ClassName]Tests.swift
📊 Test Coverage:
- [X] Nested mocks created: [count]
- [X] Test methods: [count]
- [X] Scenarios covered:
✓ Success cases
✓ Error handling
✓ Empty states
✓ Loading states
✓ Session errors (if API)
✓ Memory leak test (if ViewModel)
✓ [Other scenarios]
🎯 Test Naming Pattern:
test_methodName_condition_expectedBehavior
⚡ Next Steps:
1. Review generated tests
2. Run: xcodebuild test -scheme PayooMerchantTests
3. Or run specific plan: bundle exec fastlane run_test_plan test_plan:"[plan-name]"
📖 Generated following guide: ~/Library/Application Support/Code/User/prompts/ios-mc-generate-unit-test.prompt.md
private final classfinal class BalanceInformationViewModelTests: XCTestCase {
// MARK: - Mocks
private final class MockBalanceUseCase: BalanceUseCaseType {
var getBalanceResult: Single<Balance> = .never()
var getBalanceCallCount = 0
func getBalance() -> Single<Balance> {
getBalanceCallCount += 1
return getBalanceResult
}
}
// MARK: - Properties
private var disposeBag: DisposeBag!
private var scheduler: TestScheduler!
private var mockBalanceUC: MockBalanceUseCase!
// MARK: - Setup & Teardown
override func setUp() {
super.setUp()
disposeBag = DisposeBag()
scheduler = TestScheduler(initialClock: 0)
mockBalanceUC = MockBalanceUseCase()
}
override func tearDown() {
disposeBag = nil
scheduler = nil
mockBalanceUC = nil
super.tearDown()
}
// MARK: - Test Data Factory
private func makeTestBalance() -> Balance {
// ...
}
// MARK: - Tests
func test_transform_withLoadTrigger_shouldReturnBalance() {
// Arrange
// Act
// Assert
}
}
References:
~/Library/Application Support/Code/User/prompts/ios-mc-generate-unit-test.prompt.mdPayooMerchantTests/