Riccardo Montagnin
03/05/2019, 9:49 AMsuspend
funciton?
Let's consider this class
/**
* Allows the login of a user based on his private key.
*/
class PerformLoginUseCase internal constructor(private val repository: AuthenticationRepository){
/**
* Logs the user into the system using the given [authKey].
* @return the user data once the login has been successful.
*/
suspend operator fun invoke(authKey: PrivateKey): UserData {
return repository.login(authKey)
}
}
I have the following test
@Test
fun useCaseThrowsExceptionWhenRepositoryDoes() {
assertFailsWith(Throwable::class) {
coEvery { repository.login(any()) } throws Throwable()
GlobalScope.launch { performLogin(mockk()) }
}
}
While this should work properly, it fails with an assertionError
. I think the exception is not raised in time, so who should I do this?gildor
03/05/2019, 10:03 AMassertFailsWith(Throwable::class) {
thread { error("Some error") }
}
@Test
functions are not supported yet, but will be soon)Riccardo Montagnin
03/05/2019, 10:07 AMrunBlocking
method inside. I don't know why, but wit hthe following dependencies, it is not included:
implementation deps.kotlin.stdlib.common
implementation deps.kotlinx.coroutines.common
implementation deps.kotlin.test.common
implementation deps.kotlin.test.annotations
implementation deps.kotlinx.coroutines.test
gildor
03/05/2019, 10:07 AMRiccardo Montagnin
03/05/2019, 10:08 AMgildor
03/05/2019, 10:09 AMRiccardo Montagnin
03/05/2019, 10:09 AMgildor
03/05/2019, 10:09 AM