/android:mobiai-android-testingfrom android
Guides writing and running Android tests including unit tests with JUnit/MockK, UI tests with Espresso/Compose, and choosing the right framework and patterns.
Ships in android. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Comprehensive guide to writing and running tests in Android projects.
| Type | Location | Framework | Speed | Uses Device |
|---|---|---|---|---|
| Unit | src/test/ | JUnit + MockK | Fast | No |
| Integration | src/test/ | JUnit + Robolectric | Medium | No (simulated) |
| UI / Instrumented | src/androidTest/ | Espresso / Compose Testing | Slow | Yes |
// build.gradle.kts
dependencies {
testImplementation("junit:junit:4.13.2")
testImplementation("io.mockk:mockk:1.13.12")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0")
testImplementation("app.cash.turbine:turbine:1.2.0") // For Flow testing
}
Mirror the source path:
app/src/main/java/com/example/feature/MyViewModel.ktapp/src/test/java/com/example/feature/MyViewModelTest.ktclass MyViewModelTest {
@get:Rule
val mainDispatcherRule = MainDispatcherRule()
private val repository: MyRepository = mockk()
private lateinit var viewModel: MyViewModel
@Before
fun setUp() {
viewModel = MyViewModel(repository)
}
@Test
fun `loadData sets state to Success when repository returns data`() = runTest {
// Given
val expected = listOf(Item("1", "Test"))
coEvery { repository.getData() } returns expected
// When
viewModel.loadData()
// Then
assertEquals(UiState.Success(expected), viewModel.state.value)
coVerify(exactly = 1) { repository.getData() }
}
@Test
fun `loadData sets state to Error when repository throws`() = runTest {
// Given
coEvery { repository.getData() } throws IOException("Network error")
// When
viewModel.loadData()
// Then
assertTrue(viewModel.state.value is UiState.Error)
}
}
class MainDispatcherRule(
private val dispatcher: TestDispatcher = UnconfinedTestDispatcher()
) : TestWatcher() {
override fun starting(description: Description) {
Dispatchers.setMain(dispatcher)
}
override fun finished(description: Description) {
Dispatchers.resetMain()
}
}
// Create mock
val repo: Repository = mockk()
val repo: Repository = mockk(relaxed = true) // Returns defaults for unconfigured calls
// Stub behavior
every { repo.getData() } returns listOf(item)
coEvery { repo.fetchData() } returns result // For suspend functions
every { repo.getData() } throws IOException()
every { repo.save(any()) } just runs // Void functions
// Verify
verify { repo.getData() }
verify(exactly = 1) { repo.save(any()) }
coVerify { repo.fetchData() }
verify(exactly = 0) { repo.delete(any()) } // Never called
// Capture arguments
val slot = slot<String>()
every { repo.search(capture(slot)) } returns emptyList()
// After call: slot.captured == "search term"
// Mock objects/companions
mockkObject(MySingleton)
every { MySingleton.instance } returns mockk()
@Test
fun `events flow emits navigation event`() = runTest {
viewModel.events.test {
viewModel.onSubmitClicked()
assertEquals(Event.NavigateToSuccess, awaitItem())
cancelAndConsumeRemainingEvents()
}
}
dependencies {
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-test-manifest")
}
class MyScreenTest {
@get:Rule
val composeRule = createComposeRule()
@Test
fun submitButton_isDisabled_whenFieldIsEmpty() {
composeRule.setContent {
MyScreen(state = MyState(text = ""))
}
composeRule.onNodeWithText("Submit").assertIsNotEnabled()
}
@Test
fun errorMessage_isDisplayed_whenStateIsError() {
composeRule.setContent {
MyScreen(state = MyState(error = "Something went wrong"))
}
composeRule.onNodeWithText("Something went wrong").assertIsDisplayed()
}
}
@Test
fun clickSubmit_showsConfirmation() {
onView(withId(R.id.btn_submit)).perform(click())
onView(withText("Confirmed")).check(matches(isDisplayed()))
}
# All unit tests
./gradlew testDebugUnitTest
# Specific flavor
./gradlew test<Flavor>DebugUnitTest
# Single test class
./gradlew testDebugUnitTest --tests "com.example.MyViewModelTest"
# Single test method
./gradlew testDebugUnitTest --tests "com.example.MyViewModelTest.loadData sets state to Success*"
# Instrumented tests (requires device/emulator)
./gradlew connectedDebugAndroidTest
@Test
fun `invoke returns transformed data`() = runTest {
coEvery { repository.getItems() } returns rawItems
val result = useCase()
assertEquals(expectedTransformed, result)
}
// Use in-memory database for tests
val db = Room.inMemoryDatabaseBuilder(context, AppDatabase::class.java).build()
val dao = db.myDao()
@Test
fun `toEntity maps all fields correctly`() {
val dto = MyDto(id = "1", name = "Test", value = 42.0)
val entity = dto.toEntity()
assertEquals("1", entity.id)
assertEquals("Test", entity.name)
assertEquals(42.0, entity.value, 0.001)
}
@FlakyTest or increase timeoutsAdd to src/test/resources/mockk-extensions/io.mockk.ifc:
io.mockk.classmocking.enabled=true
Use advanceUntilIdle() or runCurrent() in runTest blocks.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub adriaanat/ecosystem-manager --plugin android10 skills in this plugin
/agp-9-upgradeUpgrades, or migrates, an Android project to use Android Gradle Plugin (AGP) version 9. Do not use this skill for migrating Kotlin Multiplatform (KMP) projects./edge-to-edgeUse this skill to migrate your Jetpack Compose app to add adaptive edge-to-edge support and troubleshoot common issues. Use this skill to fix UI components (like buttons or lists) that are obscured by or overlapping with the navigation bar or status bar, fix IME insets, and fix system bar legibility./migrate-xml-views-to-jetpack-composeProvides a structured workflow for migrating an Android XML View to Jetpack Compose. This skill details the step-by-step process, from planning and dependency setup, to theming and layout migration, validation and XML cleanup. Use this skill when you need to migrate an XML View to Jetpack Compose in an Android project. It solves the problem of converting the UI of a legacy XML View into modern, declarative Compose components while maintaining interoperability./mobiai-android-architectureUse when creating features, refactoring, or navigating an Android codebase — understand project structure, find where to make changes, follow existing patterns./mobiai-android-buildUse when building an Android project, configuring flavors or variants, troubleshooting build failures, or managing Gradle dependencies./mobiai-android-deviceUse when interacting with an Android device or emulator — run adb commands, automate UI, capture screenshots, read logcat, manage emulators.2 plugins ship this exact skill · first indexed Jul 20, 2026
Other plugins' skills for the same job