compose-testing

A set of rules and examples for testing Android screens made with Jetpack Compose. It covers checking visible text and controls, screenshot comparisons, dependency injection, background tasks, and data-flow results.

In plain words
What is it for?
Use it to write Compose screen tests, screenshot tests, coroutine tests, and checks for data streams and button actions.
Why use it?
It helps verify what users see and how screens react to clicks, loading, and completed requests. It also encourages small fake data sources instead of tests that depend on real services.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/roninforge/roninforge-kotlin-compose/compose-testing
Clone the repo
git clone --depth 1 https://github.com/RoninForge/roninforge-kotlin-compose
Per session 45 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,661 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00045 $0.01661
Opus 5 $0.00023 $0.00830
Sonnet 5 $0.00009 $0.00332
Haiku 4.5 $0.00005 $0.00166

Measured yesterday against content hash cc402d814d69, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

compose-testing scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

rules/compose-testing.mdc · 204 lines

How it starts

The opening of the file, as written. The whole thing — 204 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Compose / Kotlin Android Testing

Compose UI tests

class ProfileScreenTest {

    @get:Rule
    val rule = createComposeRule()

    @Test
    fun showsLoading() {
        rule.setContent {
            AppTheme { ProfileScreen(ProfileUiState.Loading, onIntent = {}) }
        }
        rule.onNodeWithContentDescription("Loading").assertIsDisplayed()
    }

    @Test
    fun showsUserName_onSuccess() {
        val user = User("alice", "Alice", "[email protected]")
        rule.setContent {
            AppTheme { ProfileScreen(ProfileUiState.Success(user), onIntent = {}) }
        }
        rule.onNodeWithText("Alice").assertIsDisplayed()
        rule.onNodeWithText("[email protected]").assertIsDisplayed()
    }

    @Test
    fun invokesOnIntent_whenButtonClicked() {
        val user = User("alice", "Alice", "[email protected]")
        var intent: ProfileIntent? = null
        rule.setContent {
            AppTheme {
                ProfileScreen(ProfileUiState.Success(user), onIntent = { intent = it })
            }
        }
        rule.onNodeWithText("Refresh").performClick()
        assertEquals(ProfileIntent.Refresh, intent)
    }
}

Test the stateless Screen composable. It takes state and lambdas, so the test never needs a ViewModel.

Semantic matchers

Prefer semantic queries over node-tree introspection:

  • onNodeWithText("Alice") - visible text content.
  • onNodeWithContentDescription("Profile avatar") - for icons/images.
  • onNodeWithTag("submit-button") - via Modifier.testTag(...) (use sparingly; tags are not visible to users).
  • onAllNodesWithText(...) - when multiple nodes match.

Custom matchers:

rule.onNode(hasText("Save") and hasClickAction()).performClick()

ViewModel tests with runTest + Turbine

class ProfileViewModelTest {

    @get:Rule
    val mainDispatcherRule = MainDispatcherRule()  // sets Dispatchers.Main to a test dispatcher

    @Test
    fun emitsSuccess_whenRepoReturnsUser() = runTest {
        val user = User("alice", "Alice", "[email protected]")
        val repo = FakeProfileRepository(user = user)
        // Build the route's SavedStateHandle via navigation-testing so toRoute<Profile>() works.
        val savedState = Profile("alice").let {
            SavedStateHandle().apply { set("userId", "alice") }  // see note below
        }
        val vm = ProfileViewModel(repo, savedState)

        vm.state.test {
            assertEquals(ProfileUiState.Loading, awaitItem())
            val item = awaitItem()
            assertTrue(item is ProfileUiState.Success)
            assertEquals("Alice", (item as ProfileUiState.Success).user.name)
            cancelAndIgnoreRemainingEvents()
        }
    }
}

Read the full file on GitHub · 204 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 204 lines · 45 tokens per session scan A cc402d814d69

Subscribe to this mod's changes

compose-testing is a cursor rule published in the GitHub repository RoninForge/roninforge-kotlin-compose (1 stars, last pushed 2mo ago), licensed MIT. It adds 45 tokens to every session and 1,661 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.