I wish there were an annotation `@ExistsForTesting...
# random
e
I wish there were an annotation
@ExistsForTesting
not just
@VisibleForTesting
.
😅 3
🤝 1
r
You can create your own via
@RequiresOptIn
and then opt-in only your test sources
👍 1
s
What’s the use case for
@ExistsForTesting
, anyhow?
im also not so hot on
@VisibleForTesting
myself tbh
👆 3
e
@Shawn I often create a method just to facilitate testing, for example to facilitate dependency injection when a framework is inadequate…
or to get information about private members, such as the size of a private hash map. Granted, that technically shouldn’t be a unit test, since those are about interfaces, but it’s useful for debugging and TDD.
s
Yeah that definitely shouldn’t be part of a unit test lol
my stance on it is that testing like that is brittle and often kinda misses the forest for the trees when it comes to behavioral testing
e
@Shawn Fair enough about information about private fields.
s
I’m also kinda curious what you mean by facilitating DI — ideally you’d just pass your mocks in to the constructor/factory and that’d be that, but that might not be the case if you’re doing field injection or some kind of lazy setting (also kind of a code smell imho, but still just my opinion)
e
I’m having trouble mocking Android components in some cases. https://kotlinlang.slack.com/archives/C0B8M7BUY/p1584997003143100
s
Ooh, interesting, that kinda looks like a Kotlin interop rough spot to me
I don’t work with mixed java/kotlin codebases very often and never do Android development so I’m out of my element there
e
I’m working on a prototype whose code is unlikely to be used for long (although I know those are famous last words) and am probably already over-engineering parts of it.
😂 1
s
although I know those are famous last words
too right lol
i saw in the thread that someone recommended using mockk, hopefully that works out for y’all
e
Thanks!
z
There’s a Jetbrains-specific annotation
@TestOnly
that is basically what you’re looking for, i think. https://www.jetbrains.com/help/idea/annotating-source-code.html#bundled-annotations
d
There's also
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
Neither Mockito nor MockK can mock fields afaik. But I think you can just set fields on mocks as if they were normal (non-mock) instances
e
Thanks, @Drew Hamilton, I’ll give that a try.
@Drew Hamilton That seemed to work. Thanks again!
👍 1