Kev
06/04/2024, 7:03 AMdave08
06/04/2024, 8:54 AMdave08
06/04/2024, 8:54 AMAlejandro Serrano.Mena
06/04/2024, 1:00 PMarrow-website
repoLarry Garfield
06/04/2024, 2:05 PMCLOVIS
06/04/2024, 2:12 PMinterface
! Instead of writing a system that directly accesses its dependencies, you write it to accept an interface that describes its dependency. In production code, you can give it the real implementation. In test code, you can create a new implementation that does whatever your test finds convenient. It's as simple as implementing the interface, there's no magic at all. That's a fake.Larry Garfield
06/04/2024, 2:16 PMCLOVIS
06/04/2024, 2:17 PMCLOVIS
06/04/2024, 2:20 PMKev
06/04/2024, 2:23 PMLarry Garfield
06/04/2024, 2:33 PMdave08
06/04/2024, 3:13 PMclass SLambdaFake3<A, B, R>(var result: R) : suspend (A, B) -> R {
val calledWith = mutableListOf<Pair<A, B>>()
override suspend fun invoke(a: A, b: B): R {
calledWith.add(Pair(a, b))
return result
}
fun reset() {
calledWith.clear()
}
}
the result var can be used to control the result returned and the calledWith can replace the verify { } in Mockk... a lot of fakes can be built with such patterns to make testing easier and clearer and then you don't loose your IDE type safety and refactoring features.Larry Garfield
06/04/2024, 3:15 PMRiccardo Cardin
06/05/2024, 5:01 AM