Generate UI tests for FOSMVVM SwiftUI views using XCTest and FOSTestingUI. Covers accessibility identifiers, ViewModelOperations, and test data transport.
Generate comprehensive UI tests for ViewModelViews in FOSMVVM applications.
For full architecture context, see FOSMVVMArchitecture.md | OpenClaw reference
UI testing in FOSMVVM follows a specific pattern that leverages:
CODEBLOCK0
Every project should have a base test case that inherits from ViewModelViewTestCase:
CODEBLOCK1
Key points:
ViewModel and INLINECODE2presentView() with project-specific configurationEach ViewModelView gets a corresponding UI test file.
For views WITH operations:
CODEBLOCK2
For views WITHOUT operations (display-only):
Use an empty stub operations protocol:
CODEBLOCK3
When to use each:
Common helpers for interacting with UI elements:
CODEBLOCK4
For views WITH operations:
CODEBLOCK5
For views WITHOUT operations (display-only):
CODEBLOCK6
Critical patterns (for views WITH operations):
@State private var repaintToggle = false for triggering test data transportDisplay-only views:
repaintToggle needed.testDataTransporter() modifier needed.uiTestingIdentifier() to elements you want to testNot all views need ViewModelOperations:
Views that NEED operations:
Views that DON'T NEED operations:
For views without operations:
Create an empty operations file alongside your ViewModel:
CODEBLOCK7
Then use it in tests:
CODEBLOCK8
The view itself doesn't need:
repaintToggle stateJust add .uiTestingIdentifier() to elements you want to verify.
Verify that the UI displays correctly based on ViewModel state:
CODEBLOCK9
Verify that user interactions invoke the correct operations:
CODEBLOCK10
Verify navigation flows work correctly:
CODEBLOCK11
| File | Location | Purpose |
|---|---|---|
| INLINECODE18 | INLINECODE19 | Base test case for all UI tests |
| INLINECODE20 |
Tests/UITests/Support/ | Helper extensions for XCUIElement |
| File | Location | Purpose |
|---|---|---|
| INLINECODE22 | INLINECODE23 | Operations protocol and stub (if view has interactions) |
| INLINECODE24 |
Tests/UITests/Views/{Feature}/ | UI tests for the view |
Note: Views without user interactions use an empty operations file with just the protocol and minimal stub.
| Placeholder | Description | Example |
|---|---|---|
| INLINECODE26 | Your project/app name | INLINECODE27 , INLINECODE28 |
| INLINECODE29 |
TaskList, Dashboard |
| {Feature} | Feature/module grouping | Tasks, Settings |
Invocation:
/fosmvvm-ui-tests-generator
Prerequisites:
Workflow integration:
This skill is typically used after implementing ViewModelViews. The skill references conversation context automatically—no file paths or Q&A needed. Often follows fosmvvm-swiftui-view-generator or fosmvvm-react-view-generator.
This skill references conversation context to determine test structure:
From conversation context, the skill identifies:
From requirements already in context:
Based on project state:
For the specific view:
Ensure test identifiers and data transport:
.uiTestingIdentifier() on all interactive elementsSkill references information from:
Use TestConfiguration for tests that need specific app state:
CODEBLOCK12
Define element accessors in a private extension:
CODEBLOCK13
After user interactions, verify operations were called:
CODEBLOCK14
Set device orientation in setUp() if needed:
CODEBLOCK15
All views:
.uiTestingIdentifier() on all elements you want to testViews WITH operations (interactive views):
@State private var repaintToggle = false property.testDataTransporter(viewModelOps:repaintToggle:) modifiertoggleRepaint() helper functiontoggleRepaint() called after every operation invocationoperations stored from viewModel.operations in initViews WITHOUT operations (display-only):
repaintToggle needed.testDataTransporter() neededoperations property neededoperations stored from viewModel.operations in initCODEBLOCK16
CODEBLOCK17
CODEBLOCK18
See reference.md for complete file templates.
| Concept | Convention | Example |
|---|---|---|
| Base test case | INLINECODE53 | INLINECODE54 |
| UI test file |
{ViewName}UITests | TaskListViewUITests |
| Test method (UI state) | test{Condition} | testButtonEnabled |
| Test method (operation) | test{Action} | testSubmitButton |
| Element accessor | {elementName} | submitButton, emailTextField |
| UI testing identifier | {elementName}Identifier or {elementName} | "submitButton", "emailTextField" |
| Version | Date | Changes |
|---|---|---|
| 1.0 | 2026-01-23 | Initial skill for UI tests |
| 1.1 |
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 fosmvvm-ui-tests-generator-1776420040 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 fosmvvm-ui-tests-generator-1776420040 技能
skillhub install fosmvvm-ui-tests-generator-1776420040
文件大小: 11.86 KB | 发布时间: 2026-4-17 20:03