if the recommendation is to use interfaces instead of an expect/actual, then how do you write tests for that common classes?
example:
Copy code
interface UUIDProvider {
fun randomUID(): String
}
@Test
fun randomUID_isNotEmpty() {
assertTrue(UUIDProvider().randomUID().isNotEmpty()) // we can't do that.
}
Jemo
08/14/2024, 3:48 PM
In that case we are forced to create UUIDProvider using Di right?
k
kpgalligan
08/14/2024, 4:14 PM
Use interfaces instead of
expect/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 🙂