Hello, question regarding `expect/actual` if the r...
# touchlab-tools
j
Hello, question regarding
expect/actual
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.
}
In that case we are forced to create UUIDProvider using Di right?
k
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 🙂
🙏 1