Skip to content

Commit 1a9a547

Browse files
authored
Add scoped Claude testing rule (#214)
Loads only when editing test files, covering philosophy (test user behavior, not implementation), structure, and Compose UI test patterns for Robolectric + JUnit.
1 parent 898e0e3 commit 1a9a547

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

.claude/rules/testing.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
paths: ["**/src/test/**", "**/src/androidTest/**"]
3+
---
4+
5+
# Testing Guidelines
6+
7+
## Philosophy
8+
9+
- **Test user behavior, not code structure.** Users see text, tap buttons, scroll lists. Tests should do the same. Never assert on ViewModel internals, StateFlow values, or composable parameters directly. If the user can't see it or do it, don't test it.
10+
- **Integration over unit.** Test composables with real state where possible — mock only external boundaries (network, system services).
11+
- **No mocks on business logic.** Test what the user sees after an action, not whether a function was called.
12+
13+
## Structure
14+
15+
- **Flat tests, no nesting.** Each `@Test` function is self-contained — arrange, act, assert top to bottom.
16+
- **Prefer duplication over the wrong abstraction.** Three similar tests with inline setup beats a shared helper that hides what's being tested.
17+
- **Private helper functions for test data** (like `reading(ts, sgv)`) are fine — they create data, not hide logic.
18+
19+
## Compose UI Tests
20+
21+
- Use Robolectric (`@RunWith(RobolectricTestRunner::class)`) for Compose UI tests — no emulator needed.
22+
- Query by semantics: `onNodeWithText`, `onNodeWithContentDescription`. Never use test tags unless semantics aren't available.
23+
- Wrap content in `StrimmaTheme` to match production rendering.
24+
- Use `assertDoesNotExist()` for absence, `assertIsDisplayed()` for visibility.
25+
- Use `performScrollTo()` before asserting on off-screen elements.
26+
27+
## Unit Tests
28+
29+
- Test behavior, not implementation. If a refactor breaks a test, the test was wrong.
30+
- Use real objects over mocks where possible. Mock only external boundaries (network, system services).

0 commit comments

Comments
 (0)