Does something like `@VisibleForTesting` exists in...
# test
j
Does something like
@VisibleForTesting
exists in pure Kotlin? On Android we have
android.support.annotation.VisibleForTesting
to change the visibility of properties and methods for unit tests.
t
Have you considered reworking your code so you don’t need it?
e
This only works in AS and checked by lint
So if you don’t use this for your pure Kotlin you might have problems
j
@tddmonkey I won’t need if I can convince my co-workers to not use private properties
Copy code
class MyService(
-   private val myDependency: Something
+   val myDependency: Something
)
That’s what I would prefer as well, those micro-optimization of properties visibility brings nothing IMHO.
m
why do you need to access the dependencies? Don't you inject them in tests so you can access them anyway?
j
I inject them via the constructor, making the property non-private removes a lot of boilerplat, I will use this, thanks!
t
I agree - I don’t see why you’d need the dependency to be publicly visible at all. I wouldn’t consider it micro-optimization, I would firmly put it in encapsulation and information hiding
j
I put more value on making things simple to test than on hiding information from myself for whatever value this is supposed to bring in the future. Not talking about library development here
t
you can have both 🙂
508 Views