Migrate GetCharactersPageUseCaseTest to runTest and add kotlinx-coroutines-test dependency to domain module.

This commit is contained in:
2026-06-11 10:47:08 +02:00
parent f6f81991a8
commit 9ae6e5935a
2 changed files with 7 additions and 5 deletions

View File

@@ -20,8 +20,10 @@ class DomainModuleConventionPlugin : Plugin<Project> {
add("implementation", libs.findLibrary("kotlinx-coroutines-core").get())
add("testImplementation", libs.findLibrary("junit-jupiter-api").get())
add("testImplementation", libs.findLibrary("assertk").get())
// Domain doesn't consume the `unit-test` bundle, so MockK is added explicitly here.
// Domain doesn't consume the `unit-test` bundle, so MockK and the coroutines
// test artifact are added explicitly here.
add("testImplementation", libs.findLibrary("mockk").get())
add("testImplementation", libs.findLibrary("kotlinx-coroutines-test").get())
add("testRuntimeOnly", libs.findLibrary("junit-jupiter-engine").get())
// Gradle 9 dropped the bundled launcher; JUnit 5 won't start without it.
add("testRuntimeOnly", libs.findLibrary("junit-platform-launcher").get())

View File

@@ -12,7 +12,7 @@ import com.example.architecture.feature.characters.domain.model.CharactersPage
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.mockk
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
/**
@@ -27,7 +27,7 @@ class GetCharactersPageUseCaseTest {
private val useCase = GetCharactersPageUseCase(repository)
@Test
fun `returns the repository page on success`() = runBlocking {
fun `returns the repository page on success`() = runTest {
val page = CharactersPage(characters = listOf(domainCharacter(1)), nextPage = 2)
coEvery { repository.getCharacters(1) } returns Result.Success(page)
@@ -37,7 +37,7 @@ class GetCharactersPageUseCaseTest {
}
@Test
fun `propagates the repository error`() = runBlocking {
fun `propagates the repository error`() = runTest {
coEvery { repository.getCharacters(1) } returns Result.Error(DataError.Network.SERVER_ERROR)
val result = useCase(page = 1)
@@ -47,7 +47,7 @@ class GetCharactersPageUseCaseTest {
}
@Test
fun `forwards the requested page number`() = runBlocking {
fun `forwards the requested page number`() = runTest {
coEvery { repository.getCharacters(any()) } returns
Result.Success(CharactersPage(characters = emptyList(), nextPage = null))