kotlin-testing

kotlin-testing

Kotlin testing - JUnit 5, MockK, Kotest, coroutine testing

2Sterne
1Forks
Aktualisiert 1/20/2026
SKILL.md
readonlyread-only
name
kotlin-testing
description

Kotlin testing - JUnit 5, MockK, Kotest, coroutine testing

version
"1.0.0"

Kotlin Testing Skill

Comprehensive testing with JUnit 5, MockK, and coroutine testing.

Topics Covered

MockK

class UserServiceTest {
    private val repository: UserRepository = mockk()
    private val service = UserService(repository)

    @Test
    fun `createUser saves and returns`() {
        every { repository.save(any()) } returns User(1, "test@test.com")

        val result = service.create(CreateUserRequest("test@test.com"))

        assertThat(result.id).isEqualTo(1)
        verify(exactly = 1) { repository.save(any()) }
    }
}

Coroutine Testing

@Test
fun `loadUser emits states`() = runTest {
    coEvery { repository.getUser(1) } returns Result.success(user)

    viewModel.state.test {
        viewModel.load(1)
        assertThat(awaitItem().isLoading).isTrue()
        advanceUntilIdle()
        assertThat(awaitItem().user).isEqualTo(user)
    }
}

Compose Testing

@Test
fun `button enabled when fields filled`() {
    composeTestRule.setContent { LoginScreen() }
    composeTestRule.onNodeWithTag("email").performTextInput("a@b.com")
    composeTestRule.onNodeWithTag("password").performTextInput("pass")
    composeTestRule.onNodeWithTag("login_button").assertIsEnabled()
}

Troubleshooting

Issue Resolution
"no answer found" Add every { } returns for method
Test hangs Inject TestDispatcher, use advanceUntilIdle()

Usage

Skill("kotlin-testing")

You Might Also Like

Related Skills

fix

fix

243Kdev-testing

Use when you have lint errors, formatting issues, or before committing code to ensure it passes CI.

facebook avatarfacebook
Holen
peekaboo

peekaboo

179Kdev-testing

Capture and automate macOS UI with the Peekaboo CLI.

openclaw avataropenclaw
Holen
frontend-testing

frontend-testing

128Kdev-testing

Generate Vitest + React Testing Library tests for Dify frontend components, hooks, and utilities. Triggers on testing, spec files, coverage, Vitest, RTL, unit tests, integration tests, or write/review test requests.

langgenius avatarlanggenius
Holen
frontend-code-review

frontend-code-review

127Kdev-testing

Trigger when the user requests a review of frontend files (e.g., `.tsx`, `.ts`, `.js`). Support both pending-change reviews and focused file reviews while applying the checklist rules.

langgenius avatarlanggenius
Holen
code-reviewer

code-reviewer

92Kdev-testing

Use this skill to review code. It supports both local changes (staged or working tree) and remote Pull Requests (by ID or URL). It focuses on correctness, maintainability, and adherence to project standards.

google-gemini avatargoogle-gemini
Holen
session-logs

session-logs

90Kdev-testing

Search and analyze your own session logs (older/parent conversations) using jq.

moltbot avatarmoltbot
Holen