|
| 1 | +--- |
| 2 | +name: assess-test-type |
| 3 | +description: Determines whether a test should be a UI test or unit test based on what behavior is being validated. |
| 4 | +metadata: |
| 5 | + author: dotnet-maui |
| 6 | + version: "1.0" |
| 7 | +compatibility: Requires ability to read and analyze C# test code. |
| 8 | +--- |
| 9 | + |
| 10 | +# Assess Test Type |
| 11 | + |
| 12 | +This skill determines the appropriate test type (UI test vs unit test) for tests in a PR based on what behavior they're validating. |
| 13 | + |
| 14 | +## When to Use |
| 15 | + |
| 16 | +- "Should this be a UI test or unit test?" |
| 17 | +- "What type of test is appropriate here?" |
| 18 | +- "Assess the test type for this PR" |
| 19 | +- Before running test validation |
| 20 | + |
| 21 | +## Test Type Decision Framework |
| 22 | + |
| 23 | +### When to Use Unit Tests |
| 24 | + |
| 25 | +Unit tests (xUnit) are appropriate when testing: |
| 26 | + |
| 27 | +| Scenario | Example | Location | |
| 28 | +|----------|---------|----------| |
| 29 | +| Pure logic/algorithms | String parsing, math calculations | `*.UnitTests.csproj` | |
| 30 | +| Property change notifications | `INotifyPropertyChanged` behavior | `Controls.Core.UnitTests` | |
| 31 | +| Binding expressions | Binding path resolution | `Controls.Core.UnitTests` | |
| 32 | +| XAML parsing | XAML to object graph | `Controls.Xaml.UnitTests` | |
| 33 | +| View model behavior | Command execution, state changes | `*.UnitTests.csproj` | |
| 34 | +| Platform-agnostic handlers | Handler mapping logic | `Core.UnitTests` | |
| 35 | + |
| 36 | +**Key indicators for unit tests:** |
| 37 | +- ✅ No visual rendering required |
| 38 | +- ✅ No platform-specific behavior being tested |
| 39 | +- ✅ Can mock dependencies |
| 40 | +- ✅ Tests run in milliseconds |
| 41 | +- ✅ No device/simulator needed |
| 42 | + |
| 43 | +### When to Use UI Tests |
| 44 | + |
| 45 | +UI tests (NUnit + Appium) are appropriate when testing: |
| 46 | + |
| 47 | +| Scenario | Example | Location | |
| 48 | +|----------|---------|----------| |
| 49 | +| Visual rendering | Element appears on screen | `TestCases.HostApp` + `TestCases.Shared.Tests` | |
| 50 | +| User interaction | Tap, scroll, gesture response | `TestCases.Shared.Tests` | |
| 51 | +| Platform-specific behavior | iOS SafeArea, Android back button | `TestCases.Shared.Tests` | |
| 52 | +| Layout measurement | Element size, position | `TestCases.Shared.Tests` | |
| 53 | +| Navigation | Page transitions, Shell routing | `TestCases.Shared.Tests` | |
| 54 | +| Focus/keyboard | Entry focus, keyboard appearance | `TestCases.Shared.Tests` | |
| 55 | + |
| 56 | +**Key indicators for UI tests:** |
| 57 | +- ✅ Requires visual tree to be rendered |
| 58 | +- ✅ Tests user-visible behavior |
| 59 | +- ✅ Platform-specific rendering matters |
| 60 | +- ✅ Interaction timing matters |
| 61 | +- ✅ Needs real device/simulator |
| 62 | + |
| 63 | +## Instructions |
| 64 | + |
| 65 | +### Step 1: Identify Test Files in PR |
| 66 | + |
| 67 | +```bash |
| 68 | +# Find test files |
| 69 | +git diff main --name-only | grep -E "Test|Issue" |
| 70 | + |
| 71 | +# Categorize by location |
| 72 | +# UI tests: TestCases.HostApp/, TestCases.Shared.Tests/ |
| 73 | +# Unit tests: *.UnitTests/ |
| 74 | +``` |
| 75 | + |
| 76 | +### Step 2: Analyze Each Test |
| 77 | + |
| 78 | +For each test, answer these questions: |
| 79 | + |
| 80 | +1. **Does it require rendering on screen?** |
| 81 | + - YES → Likely UI test |
| 82 | + - NO → Likely unit test |
| 83 | + |
| 84 | +2. **Does it test user interaction?** |
| 85 | + - YES → UI test |
| 86 | + - NO → Could be either |
| 87 | + |
| 88 | +3. **Is it testing platform-specific behavior?** |
| 89 | + - YES → UI test |
| 90 | + - NO → Likely unit test |
| 91 | + |
| 92 | +4. **Can it run without a device/simulator?** |
| 93 | + - YES → Unit test |
| 94 | + - NO → UI test |
| 95 | + |
| 96 | +### Step 3: Decision Flowchart |
| 97 | + |
| 98 | +``` |
| 99 | +Does it require rendering on screen? |
| 100 | +├── NO → Unit Test |
| 101 | +└── YES → Does it test user interaction? |
| 102 | + ├── YES → UI Test |
| 103 | + └── NO → Does platform-specific rendering matter? |
| 104 | + ├── YES → UI Test |
| 105 | + └── NO → Could be Unit Test (prefer Unit if possible) |
| 106 | +``` |
| 107 | + |
| 108 | +### Step 4: Check Current vs Recommended |
| 109 | + |
| 110 | +Compare what the PR has vs what it should have: |
| 111 | + |
| 112 | +```bash |
| 113 | +# Check current test type |
| 114 | +ls src/Controls/tests/TestCases.HostApp/Issues/Issue*.xaml 2>/dev/null && echo "Has UI test" |
| 115 | +ls src/Controls/tests/*UnitTests/**/Issue*.cs 2>/dev/null && echo "Has unit test" |
| 116 | +``` |
| 117 | + |
| 118 | +## Output Format |
| 119 | + |
| 120 | +```markdown |
| 121 | +## Test Type Assessment |
| 122 | + |
| 123 | +### Tests in PR |
| 124 | + |
| 125 | +| Test | Current Type | Recommended | Reasoning | |
| 126 | +|------|--------------|-------------|-----------| |
| 127 | +| [TestName] | UI Test | UI Test ✅ | Requires user interaction | |
| 128 | +| [TestName] | UI Test | Unit Test ❌ | Pure logic, no rendering needed | |
| 129 | +| [TestName] | Unit Test | Unit Test ✅ | Tests binding resolution | |
| 130 | + |
| 131 | +### Recommendation |
| 132 | + |
| 133 | +- ✅ Test types are appropriate |
| 134 | +- OR |
| 135 | +- ⚠️ Consider changing [TestName] from [current] to [recommended] because [reason] |
| 136 | + |
| 137 | +### Next Steps |
| 138 | + |
| 139 | +Based on test types present: |
| 140 | +- For UI tests → Use `validate-ui-tests` skill |
| 141 | +- For unit tests → Use `validate-unit-tests` skill |
| 142 | +``` |
| 143 | + |
| 144 | +## Examples |
| 145 | + |
| 146 | +### Example 1: RadioButton Binding in CollectionView |
| 147 | + |
| 148 | +**Issue**: RadioButtonGroup.SelectedValue binding doesn't update when RadioButton is checked inside CollectionView |
| 149 | + |
| 150 | +**Analysis**: |
| 151 | +- Requires visual rendering? YES (RadioButtons must appear) |
| 152 | +- Tests user interaction? YES (tapping RadioButton) |
| 153 | +- Platform-specific? NO (cross-platform binding issue) |
| 154 | + |
| 155 | +**Verdict**: UI Test ✅ |
| 156 | + |
| 157 | +### Example 2: String Parsing Logic |
| 158 | + |
| 159 | +**Issue**: Custom markup extension fails to parse certain string formats |
| 160 | + |
| 161 | +**Analysis**: |
| 162 | +- Requires visual rendering? NO |
| 163 | +- Tests user interaction? NO |
| 164 | +- Platform-specific? NO |
| 165 | + |
| 166 | +**Verdict**: Unit Test ✅ |
| 167 | + |
| 168 | +### Example 3: Layout Calculation |
| 169 | + |
| 170 | +**Issue**: Grid column width incorrect when using star sizing |
| 171 | + |
| 172 | +**Analysis**: |
| 173 | +- Requires visual rendering? YES (layout must be measured) |
| 174 | +- Tests user interaction? NO |
| 175 | +- Platform-specific? MAYBE (could differ per platform) |
| 176 | + |
| 177 | +**Verdict**: UI Test ✅ (layout measurement requires rendering) |
0 commit comments