Composables

Android Kotlin Testing

Community

haidrrrry

Android testing patterns — ViewModel unit tests with Turbine, Compose UI semantics, Hilt TestInstallIn fakes, coroutine test dispatchers, and release quality gates. Use when writing tests, setting up CI, mocking repositories, or asking "how to test ViewModel", "Compose UI test", "Turbine StateFlow".

Overview

Repository
haidrrrry/compose-kotlin-agent-skills
Publisher
haidrrrry
Stars
65
Forks
8
Bundled files
0
License
MIT
Updated
Jul 8, 2026

Installation

tmp=$(mktemp -d)
git clone --depth 1 https://github.com/haidrrrry/compose-kotlin-agent-skills.git "$tmp"
mkdir -p ~/.claude/skills
cp -R "$tmp/skills/android-kotlin-testing" ~/.claude/skills/android-kotlin-testing
rm -rf "$tmp"

Instructions

Android Kotlin — Testing Module

Parent kit: ../../SKILL.md · Index: ../../AGENTS.md

Read First

File When
../../references/11-testing.md Turbine, fakes, Compose test tags
../../references/05-hilt-di.md TestInstallIn modules
../../references/13-release-checklist.md Pre-ship checklist

ViewModel Test Template

@OptIn(ExperimentalCoroutinesApi::class)
class FeatureViewModelTest {

    @get:Rule
    val mainDispatcherRule = MainDispatcherRule()

    private val fakeRepo = FakeFeatureRepository()
    private lateinit var viewModel: FeatureViewModel

    @Before
    fun setup() {
        viewModel = FeatureViewModel(fakeRepo)
    }

    @Test
    fun `refresh success clears loading`() = runTest {
        fakeRepo.syncResult = Result.success(Unit)

        viewModel.onEvent(FeatureUiEvent.Refresh)

        viewModel.state.test {
            skipItems(1)
            val loading = awaitItem()
            assertTrue(loading.isLoading)
            val done = awaitItem()
            assertFalse(done.isLoading)
            assertNull(done.error)
        }
    }
}

Fake Over Mock

class FakeFeatureRepository : FeatureRepository {
    var syncResult: Result<Unit> = Result.success(Unit)
    private val items = MutableStateFlow<List<Feature>>(emptyList())

    override fun observeItems(): Flow<List<Feature>> = items
    override suspend fun sync(): Result<Unit> = syncResult
}

Prefer fakes implementing real interfaces — tests behavior, not interaction order.

Compose UI Test

class FeatureScreenTest {
    @get:Rule
    val composeRule = createComposeRule()

    @Test
    fun showsEmptyState() {
        composeRule.setContent {
            AppTheme {
                FeatureContent(
                    state = FeatureUiState(items = emptyList()),
                    onEvent = {}
                )
            }
        }
        composeRule.onNodeWithTag("feature_empty").assertIsDisplayed()
    }
}

Test stateless FeatureContent, not ViewModel-integrated screen.

What to Test vs Skip

Always test Usually skip
ViewModel state transitions Room generated SQL
Repository mappers Hilt graph wiring (compile-time)
Error paths (Result.failure) Pixel-perfect screenshots
Critical user flows (instrumented) Third-party SDK internals

CI Gate

Repo skill validation must pass before merge:

python3 scripts/validate_skills.py --strict

FAQ

What does Android Kotlin Testing do?

Android testing patterns — ViewModel unit tests with Turbine, Compose UI semantics, Hilt TestInstallIn fakes, coroutine test dispatchers, and release quality gates. Use when writing tests, setting up CI, mocking repositories, or asking "how to test ViewModel", "Compose UI test", "Turbine StateFlow".

Who made Android Kotlin Testing?

haidrrrry (a community member) publishes it in the haidrrrry/compose-kotlin-agent-skills repository on GitHub.

Is Android Kotlin Testing free?

Yes. Android Kotlin Testing is open source, published by haidrrrry under the MIT license.

What comes with Android Kotlin Testing?

Just its instructions. Everything the agent needs is in one SKILL.md file.

Which agents can use Android Kotlin Testing?

Any coding agent that reads SKILL.md files, including Claude Code, Codex, Cursor, GitHub Copilot and Gemini CLI. The agent loads the skill when a task matches its description.

What are agent skills?

An agent skill is a folder with a SKILL.md file: instructions that teach a coding agent how to do one kind of task, and optionally files it can read while it works. The agent keeps only the skill's name and description in mind and reads the rest when a task calls for it.

How are agent skills different from MCP servers?

An MCP server gives an agent new tools to call, code that runs somewhere and returns results. A skill gives it knowledge: how to approach a task with the tools it already has. Many agents use both.

How can my agent test my Android app?

Robomori lets coding agents create, start and control Android emulators and devices from one command, so they can install your app, take screenshots and check dark mode, font sizes and languages.

You're subscribed

The next lesson lands in on Wednesday.