xiaohongshu
xiaohongshu
ios-generate-unit-tests
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",...
Full skill instructions
Automatically 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/xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience