-
Notifications
You must be signed in to change notification settings - Fork 0
Test Repository
Ali Sadeghi edited this page Feb 5, 2026
·
6 revisions
Generates Repository tests using Mokkery for mocking.
Spawned by: feature-test command
- Success case delegation to DataSource
- Error propagation (all ErrorConst types)
- Data transformation (DTO to domain mapping)
- Parameter passing verification
- Boundary conditions (max/min values, empty lists)
- Caching behavior (if applicable)
class LoginRepositoryImplTest {
private val remoteDataSource = mock<LoginRemoteDataSource>()
private lateinit var repository: LoginRepositoryImpl
@BeforeTest
fun setup() {
repository = LoginRepositoryImpl(remoteDataSource = remoteDataSource)
}
@AfterTest
fun teardown() {
resetAnswers(remoteDataSource)
}
@Test
fun `login returns mapped user on success`() = runTest {
val response = LoginFixtures.createLoginResponse()
everySuspend { remoteDataSource.login(any()) } returns Either.Success(response)
val result = repository.login(LoginFixtures.createLoginRequest())
assertTrue(result is Either.Success)
assertEquals(response.user.id, (result as Either.Success).value.id)
}
@Test
fun `login propagates network failure`() = runTest {
everySuspend { remoteDataSource.login(any()) } returns
Either.Failure(LoginFixtures.networkError) // ErrorConst.NoNetwork
val result = repository.login(LoginFixtures.createLoginRequest())
assertTrue(result is Either.Failure)
assertEquals(LoginFixtures.networkError, (result as Either.Failure).error)
}
@Test
fun `login propagates unauthorized error`() = runTest {
everySuspend { remoteDataSource.login(any()) } returns
Either.Failure(LoginFixtures.unauthorizedError) // ErrorConst.Unauthorized
val result = repository.login(LoginFixtures.createLoginRequest())
assertTrue(result is Either.Failure)
assertEquals(LoginFixtures.unauthorizedError, (result as Either.Failure).error)
}
@Test
fun `login passes correct parameters to dataSource`() = runTest {
val request = LoginFixtures.createLoginRequest(email = "test@example.com")
everySuspend { remoteDataSource.login(any()) } returns
Either.Success(LoginFixtures.createLoginResponse())
repository.login(request)
verifySuspend { remoteDataSource.login(request) }
}
}- Uses
everySuspendandverifySuspendfor suspend functions - Uses
resetAnswers()in@AfterTestfor clean state - Error fixtures use
ErrorConstconstants - Verifies both success data and error propagation
Back to Testing Agents | Agents