Do you guys think `@VisibleForTesting` a bad pract...
# android
a
Do you guys think
@VisibleForTesting
a bad practice for unit testing internals of a component?
d
Yes, is bad practice. For example, create some test component with generic interface.
a
I mean, if I want to test an internal method which will get called internally by another internal component, instead of setting up all that boilerplate up. I just set it
@VisibleForTesting
and unit test it directly.
m
I don’t think it’s so bad (especially after reading Working Effectively with Legacy Code), however the linting in Android Studio doesn’t seem to work for Kotlin like it does in Java
r
It’s a smell, but you gotta do what you gotta do
Generally a hint that you might be testing implementation details, or are missing some DI. When the landmine blows up it’s because you’re not testing the bits that call the method that should have been private.
a
Agree, but in the tradeoff scale between boilerplate for setting up proper integration test and just testing this implementation details paid off in my case (at least in my opinion)
Sometimes, building a integration test is so expensive that devs just don't do it.
c
usually when i need to test functionality that’s inside of a component it’s a sign that i should extract that into it’s own class that the other class can rely on
👍 5
a
Fair enough
s
Keep in mind that now you’ve coupled your internal implementation to your test implementation, and now you’re not easily able to change the internals should the need arise
a
Actually I have refactored it into a delegate + factory based on comments here. I was being really lazy and trying to justify my laziness