Jemo
08/14/2024, 3:47 PMexpect/actual
if the recommendation is to use interfaces instead of an expect/actual, then how do you write tests for that common classes?
example:
interface UUIDProvider {
fun randomUID(): String
}
@Test
fun randomUID_isNotEmpty() {
assertTrue(UUIDProvider().randomUID().isNotEmpty()) // we can't do that.
}
Jemo
08/14/2024, 3:48 PMkpgalligan
08/14/2024, 4:14 PMexpect/actual
for classes. In this case, if you didn't want to deal with DI, I'd suggest writing expect/actual
factory functions to create the platform-specific interface implementation. expect/actual
factory functions are also useful in main code for default implementations, while still allowing for injected ones. In that scenario, just remember to make those factory functions internal 🙂