In one of my projects, I am using expect/actual fo...
# multiplatform
l
In one of my projects, I am using expect/actual for platform-specific behaviour. I now need my tests to be able to override this behaviour if possible (for example, having an actual class in both androidMain and androidTest). I would like the actual from the test source set to be used in tests, even in code in commonMain. Is this possible? When I define an actual class in androidTest, it complains that there's no expect declaration.
a
I do not think that this is possible. Consider using interface
t
Yes ditto, consider using interfaces
If you cannot for some reason, mockk works on JVM, which we use. And there’s this new kid on the block, mockative which I have not tried
l
I'll likely use an interface. My current use case is SQLDelight, which uses platform-dependent drivers. I would like to use a different driver for unit tests.
t
Solid plan!
For integration tests, if you wish to write them, your 3rd party libraries may not have interfaces, and that’s where these mocking libraries shine.
l
I may have to do some refactoring, since I originally assumed I could just add an actual class for tests.
t
interfaces have the added benefit that you could have multiple implementations on one platform, if you needed to.
l
That's fair.