https://kotlinlang.org logo
#android
Title
# android
a

alex.tavella

08/14/2019, 5:12 PM
Do you guys think
@VisibleForTesting
a bad practice for unit testing internals of a component?
d

Dmitry Chernozubov

08/14/2019, 5:19 PM
Yes, is bad practice. For example, create some test component with generic interface.
a

alex.tavella

08/14/2019, 5:32 PM
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

Matt Thompson

08/14/2019, 5:36 PM
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

Ray Ryan

08/14/2019, 6:15 PM
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

alex.tavella

08/14/2019, 6:23 PM
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

Cody Engel

08/14/2019, 7:10 PM
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

alex.tavella

08/14/2019, 8:52 PM
Fair enough
s

Steve

08/15/2019, 3:55 PM
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

alex.tavella

08/15/2019, 6:16 PM
Actually I have refactored it into a delegate + factory based on comments here. I was being really lazy and trying to justify my laziness
5 Views