Let's say I have a test class with some mocks in it. Lint suggests that the fields can be private. I'm wondering, is there any problem in making them private? One of my colleagues thinks that perhaps it will cause Mockito to use reflection. Is this true or can I safely mark them as private?
@Mock private Context context;
vs
@Mock Context context;
The official Android documentation has private on the Kotlin version but not on the Java version (at the time of writing this question). https://developer.android.com/training/testing/unit-testing/local-unit-tests#kotlin
I've looked around and Googled but I'm not sure since it's not mentioned explicitly anywhere that I could find, and some references have private while others don't.
The tests run fine in both cases and take around the same time (10 seconds). So for that reason I think it's better to mark as private and remove the lint error. What could possibly be the downside?
As far as I can tell, reflection has nothing to do with the value being private or not. It seems that it's more about whether it can see the methods inside the mock class. If those methods inside the class are private then it will need to use reflection.