Professional Unit Test Skill for Cursor IDE - Multi-platform UT generation with auto error fixing
npm install mthor-ut-skillA comprehensive unit test generation skill for iOS, Android, and C++ platforms.
Simply type one of these commands in the chat:
``bashGenerate UT for all changed files (compared to develop branch)
ut_changed
Commands
$3
Analyzes git changes and generates unit tests for modified files.
`bash
ut_changed [--base=] [--platform=]
`| Parameter | Default | Description |
|-----------|---------|-------------|
|
--base | origin/dev | Base branch for comparison (uses remote to avoid stale local) |
| --platform | all | Filter by platform |Examples:
`bash
ut_changed
ut_changed --base=origin/dev
ut_changed --base=origin/main --platform=ios
`$3
Generates unit tests for all source files in a directory.
`bash
ut_path --path= [--platform=]
`| Parameter | Required | Description |
|-----------|----------|-------------|
|
--path | Yes | Directory path to scan |
| --platform | No | Filter by platform |Examples:
`bash
ut_path --path=phone/ios/Phone/Service
ut_path --path=video/android/module-video/src/main/java/com/glip/video
ut_path --path=phone/cpp/core-phone/src --platform=cpp
`$3
Generates unit tests for specific files.
`bash
ut_files --files="" [--platform=]
`| Parameter | Required | Description |
|-----------|----------|-------------|
|
--files | Yes | Comma-separated file list |
| --platform | No | Filter by platform |Examples:
`bash
ut_files --files="UserService.swift,AuthManager.swift"
ut_files --files="PhoneService.kt" --platform=android
`Workflow
The skill executes the following workflow:
$3
- Detects changed files (local + branch diff)
- Filters by platform
- Excludes test files and non-testable files$3
- Maps source files to test file locations
- Checks if test file already exists$3
- Reads source file for analysis
- Finds similar tests for reference
- Identifies existing test coverage$3
- Generates tests following platform rules
- Achieves 100% branch coverage
- Achieves 100% code coverage
- Updates existing tests (no duplicates)$3
- Prompts user to choose:
- make ios_install_with_source
- make ios_install_with_binary_cache$3
- Runs generated tests
- Collects coverage data$3
- Displays line coverage
- Displays branch coverage
- Identifies missing coverageCoverage Requirements
All generated tests must achieve:
- ✅ 100% Line Coverage
- ✅ 100% Branch Coverage
Platform Rules
The skill follows platform-specific testing rules:
| Platform | Rule File |
|----------|-----------|
| iOS |
.cursor/rules/unit-test/ios-unit-test.mdc |
| Android | .cursor/rules/unit-test/android-unit-test.mdc |
| C++ | .cursor/rules/unit-test/cpp-unit-test.mdc |
| Common | .cursor/rules/unit-test/unit-testing-principles.mdc |Test Path Conventions
$3
`
Source: phone/ios/Phone/Service/PhoneService.swift
Test: phone/ios/Phone/Tests/PhoneServiceTests.swift
`$3
`
Source: phone/android/module-phone/src/main/java/.../PhoneService.kt
Test: phone/android/module-phone/src/test/java/.../PhoneServiceTest.kt
`$3
`
Source: phone/cpp/core-phone/src/cc_lt/live_transcript_service.cpp
Test: phone/cpp/core-phone/tests/src/cc_lt/live_transcript_service_test.cpp
`Base Test Classes
| Platform | Base Class | Location |
|----------|------------|----------|
| iOS |
XCBaseTestCase | common/ios/Common/UnitTestCommon/ |
| Android | BaseRobolectricTest | Module test directories |
| C++ | InitGlipCoreTest | */tests/ut_base/ |Templates
Reference templates are available in:
-
templates/ios-test-template.swift
- templates/android-test-template.kt
- templates/cpp-test-template.cppFile Structure
`
.cursor/skills/ut-skill/
├── README.md # This file
├── skill.md # Skill overview
├── workflow.md # Detailed workflow steps
├── trigger.mdc # Command trigger rule
├── prompts/
│ ├── ut_changed.md # ut_changed command prompt
│ ├── ut_path.md # ut_path command prompt
│ └── ut_files.md # ut_files command prompt
└── templates/
├── ios-test-template.swift
├── android-test-template.kt
└── cpp-test-template.cpp
``1. No Duplicates: Never create duplicate test files or methods
2. Update Mode: Modify existing tests rather than recreating
3. Reference Patterns: Use similar tests in the module as reference
4. Follow Standards: Strictly follow platform testing guidelines
5. Complete Coverage: Test all branches and code paths