I took the time to find a way to write instrumented tests for the Kotlin code that's been written so far. Now we need to add more tests to cover all the Activity, Fragment, and Adapter classes that don't have coverage yet.
Some additional background:
Classes are final by default in Kotlin -- that means certain additional dependencies are required in order to mock them.
When using Mockito for unit tests, mockito-inline takes care of this.
However, in instrumented tests, mockito-inline doesn't play nice with mockito-android. Adding the MockMaker file manually doesn't work either. It appears this feature isn't supported for instrumented tests.
We could use a library called all-open, but that requires us to annotate all the classes we mock, as well as additional configuration so that classes are only made open in debug builds.
Other approaches to using Mockito exist, too, but I've only been using Mockito so far because it's the mocking framework I'm most familiar with. At this point, I decided it would be good to try a framework that's been developed specifically with Kotlin in mind, so I gave MockK a shot. This was much easier to get working! The only caveat is that it requires instrumented tests to run on a device or simulator with Android P (9.0) or above. However, I think that's reasonable enough since it only applies to instrumented tests. It doesn't affect the minSdkVersion of our app.
The upshot of this is that we have a potential strategy for writing instrumented tests. The other variable I'd like to consider is whether or not to use Robolectric, but for now I'd like to see how far we can get without it.
I took the time to find a way to write instrumented tests for the Kotlin code that's been written so far. Now we need to add more tests to cover all the Activity, Fragment, and Adapter classes that don't have coverage yet.
Some additional background:
Other approaches to using Mockito exist, too, but I've only been using Mockito so far because it's the mocking framework I'm most familiar with. At this point, I decided it would be good to try a framework that's been developed specifically with Kotlin in mind, so I gave MockK a shot. This was much easier to get working! The only caveat is that it requires instrumented tests to run on a device or simulator with Android P (9.0) or above. However, I think that's reasonable enough since it only applies to instrumented tests. It doesn't affect the minSdkVersion of our app.
The upshot of this is that we have a potential strategy for writing instrumented tests. The other variable I'd like to consider is whether or not to use Robolectric, but for now I'd like to see how far we can get without it.