|
| 1 | +# Test Suite Consolidation Plan |
| 2 | + |
| 3 | +**Issue:** [#174 - Test suite getting bloated](https://github.com/williscool/CalendarNotification/issues/174) |
| 4 | + |
| 5 | +**Coverage Baseline:** See `docs/coverage-baseline/BASELINE-SUMMARY.md` |
| 6 | + |
| 7 | +## Current State |
| 8 | + |
| 9 | +| Category | Files | Lines of Code | |
| 10 | +|----------|-------|---------------| |
| 11 | +| Unit Tests (Robolectric) | ~50 | ~18,582 | |
| 12 | +| Integration Tests (Instrumented) | ~45 | ~19,743 | |
| 13 | +| **Total** | ~95 | **~38,325** | |
| 14 | + |
| 15 | +## Analysis Summary |
| 16 | + |
| 17 | +### Coverage Baseline (Pre-Consolidation) |
| 18 | + |
| 19 | +| Metric | Unit Tests | Integration Tests | |
| 20 | +|--------|------------|-------------------| |
| 21 | +| Instruction Coverage | 25.97% | 43.79% | |
| 22 | +| Branch Coverage | 21.80% | 31.07% | |
| 23 | +| Line Coverage | 24.84% | 45.34% | |
| 24 | +| Method Coverage | 34.30% | 46.07% | |
| 25 | + |
| 26 | +### Key Findings |
| 27 | + |
| 28 | +1. **Massive Duplication**: ~20 test classes exist as BOTH Robolectric (unit) AND instrumented (integration) versions with nearly identical tests |
| 29 | +2. **Deprecated Tests**: ~5,000 lines in `deprecated_raw_calendarmonitor/` folder that should be removed or archived |
| 30 | +3. **Testing Overly Simple Logic**: Some tests verify trivial functionality that could be simplified |
| 31 | +4. **Large Monolithic Tests**: Several test files exceed 700+ lines and could be split or simplified |
| 32 | + |
| 33 | +--- |
| 34 | + |
| 35 | +## Consolidation Plan |
| 36 | + |
| 37 | +### Phase 1: Remove Deprecated Tests (~5,000 lines reduction) |
| 38 | + |
| 39 | +**Target Directory:** `app/src/androidTest/java/.../deprecated_raw_calendarmonitor/` |
| 40 | + |
| 41 | +| File | Lines | Action | |
| 42 | +|------|-------|--------| |
| 43 | +| `CalendarMonitorServiceTest.kt` | 2,001 | DELETE - replaced by `FixturedCalendarMonitorServiceTest` | |
| 44 | +| `CalendarMonitorServiceTestFirstScanEver.kt` | 2,034 | DELETE - covered by newer tests | |
| 45 | +| `CalendarMonitorServiceEventReminderTest.kt` | 966 | DELETE - functionality tested elsewhere | |
| 46 | + |
| 47 | +**Verification:** Run integration tests after removal to ensure no functionality gaps. |
| 48 | + |
| 49 | +--- |
| 50 | + |
| 51 | +### Phase 2: Consolidate Duplicate Test Pairs (~5,000-7,000 lines reduction) |
| 52 | + |
| 53 | +For tests that exist in both unit AND integration form with nearly identical logic, consolidate to ONE version (preferring Robolectric for speed, keeping instrumented only where Android runtime is essential). |
| 54 | + |
| 55 | +#### Priority 1 - Direct Duplicates (Pure Logic Tests - Keep Robolectric Only) |
| 56 | + |
| 57 | +These tests verify pure Kotlin/Java logic that doesn't require real Android runtime: |
| 58 | + |
| 59 | +| Test Pair | Unit Lines | Int Lines | Action | |
| 60 | +|-----------|------------|-----------|--------| |
| 61 | +| `TagsManager*Test.kt` | 206 | 205 | **DELETE integration** - pure string parsing | |
| 62 | +| `AlarmScheduler*Test.kt` | 282 | 289 | **KEEP BOTH** - integration verifies real AlarmManager | |
| 63 | +| `CalendarReloadManager*Test.kt` | 292 | 283 | **DELETE integration** - logic can be tested with mocks | |
| 64 | +| `SnoozeTest.kt` / `SnoozeRobolectricTest.kt` | 334 | 380 | **DELETE integration** - snooze logic testable with mocks | |
| 65 | +| `ComponentIsolation*Test.kt` | 319 | 297 | **DELETE integration** - isolation tests work in Robolectric | |
| 66 | + |
| 67 | +**Estimated Reduction:** ~1,400 lines |
| 68 | + |
| 69 | +#### Priority 2 - UI Tests (Keep Integration, Delete/Reduce Robolectric) |
| 70 | + |
| 71 | +UI tests benefit from real Android runtime. Robolectric UI tests are often flaky or limited: |
| 72 | + |
| 73 | +| Test Pair | Unit Lines | Int Lines | Action | |
| 74 | +|-----------|------------|-----------|--------| |
| 75 | +| `MainActivityModernTest.kt` | 775 | 873 | **REVIEW** - consider keeping integration only | |
| 76 | +| `MainActivityTest.kt` | 367 | 460 | **REVIEW** - may consolidate with Modern | |
| 77 | +| `ViewEventActivityTest.kt` | 383 | 306 | **REVIEW** - prefer integration for UI | |
| 78 | +| `SnoozeAllActivityTest.kt` | N/A | 279 | **KEEP** - no Robolectric version | |
| 79 | + |
| 80 | +**Estimated Reduction:** ~500-1,000 lines (after review) |
| 81 | + |
| 82 | +#### Priority 3 - CalendarProvider Tests (Keep Integration) |
| 83 | + |
| 84 | +CalendarProvider tests require real ContentProvider access: |
| 85 | + |
| 86 | +| Test Pair | Unit Lines | Int Lines | Action | |
| 87 | +|-----------|------------|-----------|--------| |
| 88 | +| `CalendarProviderBasicTest.kt` | 349 | 270 | **DELETE Robolectric** - needs real ContentProvider | |
| 89 | +| `CalendarProviderEventTest.kt` | 314 | 276 | **DELETE Robolectric** - needs real ContentProvider | |
| 90 | +| `CalendarProviderReminderTest.kt` | 340 | 315 | **DELETE Robolectric** - needs real ContentProvider | |
| 91 | +| `CalendarBackupRestoreTest.kt` | 289 | 333 | **DELETE Robolectric** - needs real storage | |
| 92 | + |
| 93 | +**Estimated Reduction:** ~1,300 lines |
| 94 | + |
| 95 | +#### Priority 4 - Storage/Database Tests (Keep Integration) |
| 96 | + |
| 97 | +Storage tests benefit from real SQLite/Room: |
| 98 | + |
| 99 | +| Test Pair | Unit Lines | Int Lines | Action | |
| 100 | +|-----------|------------|-----------|--------| |
| 101 | +| `EventDismissTest.kt` | 726 | 735 | **DELETE Robolectric** - needs real Room | |
| 102 | +| `OriginalEventDismiss*Test.kt` | 318 | ~300 | **DELETE Robolectric** - needs real Room | |
| 103 | + |
| 104 | +**Estimated Reduction:** ~1,000 lines |
| 105 | + |
| 106 | +#### Priority 5 - Broadcast Receiver Tests (Keep Both, Reduce Overlap) |
| 107 | + |
| 108 | +Some broadcast tests need real Android, others can be unit tested: |
| 109 | + |
| 110 | +| Test Pair | Unit Lines | Int Lines | Action | |
| 111 | +|-----------|------------|-----------|--------| |
| 112 | +| `BroadcastReceiverTest.kt` | 356 | 315 | **MERGE** - combine unique tests, remove duplicates | |
| 113 | +| `ReminderAlarmTest.kt` | 422 | 305 | **MERGE** - keep real alarm behavior in integration | |
| 114 | + |
| 115 | +**Estimated Reduction:** ~300 lines |
| 116 | + |
| 117 | +--- |
| 118 | + |
| 119 | +### Phase 3: Simplify Large Tests |
| 120 | + |
| 121 | +#### Tests to Review for Simplification |
| 122 | + |
| 123 | +| File | Lines | Opportunity | |
| 124 | +|------|-------|-------------| |
| 125 | +| `EventNotificationManagerRobolectricTest.kt` | 1,480 | Extract helper methods, reduce setup boilerplate | |
| 126 | +| `NotificationContextInvariantTest.kt` | 999 | Review if all cases are necessary | |
| 127 | +| `EventFormatterRobolectricTest.kt` | 956 | Consider parameterized tests | |
| 128 | +| `MainActivityModernTest.kt` | 873 | Split into focused feature tests | |
| 129 | +| `SettingsBackupManagerRobolectricTest.kt` | 760 | Use shared fixtures | |
| 130 | +| `EventDismissTest.kt` | 735 | Consolidate similar test cases | |
| 131 | +| `EventsStorageMigrationTest.kt` | 637 | Consider if all migration paths need testing | |
| 132 | + |
| 133 | +**Estimated Reduction:** ~500-1,500 lines through refactoring |
| 134 | + |
| 135 | +--- |
| 136 | + |
| 137 | +### Phase 4: Consolidate Test Fixtures |
| 138 | + |
| 139 | +| Fixture Pair | Lines | Action | |
| 140 | +|--------------|-------|--------| |
| 141 | +| `UITestFixture.kt` | 978 | **MERGE** - combine shared utilities | |
| 142 | +| `UITestFixtureRobolectric.kt` | 551 | Into single fixture with platform-specific overrides | |
| 143 | +| `CalendarProviderTestFixture.kt` | 414 | **KEEP** - integration only | |
| 144 | +| `CalendarMonitorTestFixture.kt` | 398 | **KEEP** - integration only | |
| 145 | +| `BaseCalendarTestFixture.kt` | 531 | **KEEP** - base class | |
| 146 | + |
| 147 | +**Estimated Reduction:** ~400 lines |
| 148 | + |
| 149 | +--- |
| 150 | + |
| 151 | +## Implementation Order |
| 152 | + |
| 153 | +### Batch 1: Low-Risk Deletions (No coverage loss expected) |
| 154 | +1. Delete `deprecated_raw_calendarmonitor/` folder (~5,000 lines) |
| 155 | +2. Delete `TagsManagerTest.kt` (integration) - keep Robolectric version |
| 156 | +3. Delete CalendarProvider Robolectric tests (keep integration versions) |
| 157 | + |
| 158 | +### Batch 2: Consolidations Requiring Verification |
| 159 | +4. Merge BroadcastReceiver test pairs |
| 160 | +5. Consolidate EventDismiss test pairs |
| 161 | +6. Review and consolidate SnoozeTest pairs |
| 162 | + |
| 163 | +### Batch 3: UI Test Consolidation |
| 164 | +7. Review MainActivity test strategy |
| 165 | +8. Consolidate UI test fixtures |
| 166 | + |
| 167 | +### Batch 4: Refactoring Large Tests |
| 168 | +9. Apply shared fixtures to large test files |
| 169 | +10. Use parameterized tests where applicable |
| 170 | + |
| 171 | +--- |
| 172 | + |
| 173 | +## Success Criteria |
| 174 | + |
| 175 | +1. **No Coverage Regression**: Coverage percentages should remain at or above baseline |
| 176 | +2. **Test Count Reduction**: Target 20-30% reduction in total test lines |
| 177 | +3. **Test Speed**: Unit test suite should run faster (fewer duplicate runs) |
| 178 | +4. **Maintainability**: Clear separation of unit vs integration test responsibilities |
| 179 | + |
| 180 | +--- |
| 181 | + |
| 182 | +## Estimated Total Reduction |
| 183 | + |
| 184 | +| Phase | Lines Removed | |
| 185 | +|-------|---------------| |
| 186 | +| Phase 1: Deprecated | ~5,000 | |
| 187 | +| Phase 2: Duplicates | ~4,500 | |
| 188 | +| Phase 3: Simplify | ~1,000 | |
| 189 | +| Phase 4: Fixtures | ~400 | |
| 190 | +| **Total** | **~10,900 lines (28% reduction)** | |
| 191 | + |
| 192 | +**Post-Consolidation Target:** ~27,000 lines (down from ~38,000) |
| 193 | + |
| 194 | +--- |
| 195 | + |
| 196 | +## Notes |
| 197 | + |
| 198 | +- Always verify coverage after each batch |
| 199 | +- Run full test suite before and after changes |
| 200 | +- Document any intentional coverage reductions with justification |
| 201 | +- Keep integration tests for anything that truly requires Android runtime |
0 commit comments