I think I’ve finally reached a place of peace with...
# minutest
r
I think I’ve finally reached a place of peace with using mocks in fixtures
☮️ 1
d
I find my Kotlin uses mocks a lot less than my Java. My experience is that most classes rely on only method of a collaborator, in which case I tend to just supply a function argument
c
i do that too
r
hmm interesting. I guess because I’m primarily working on Spring Boot that would ironically take more configuration for me. (I’d have to declare
@Bean
methods rather than just using
@Component
annotations
c
can you expand on that? I’m still not 100% what to think about spring boot
r
Basically you can annotate a class with
@Component
and collaborators will get auto-wired or you can use an configuration class with a method annotated
@Bean
that explicitly registers the component. Usually you do the latter if you need the component to be conditional or have a non-trivial auto-wiring case, e.g. in this case you want to pass a single method of another bean as a function param to the component’s constructor rather than wiring in the entire other bean.
It’s pretty easy either way, but with
@Component
you can save the effort of writing a factory method in a special configuration class.
c
i always wire my beans manually in tests because then the test gets ugly when my dependencies become too complex.
r
Oh for sure, in tests, yes
I will probably have a small handful of integration tests that are basically checking I’m wiring things up correctly, but the vast majority will be unit level tests where I’m manually wiring things up. However, I’m thinking more about the fact that the choice to use @Component annotated beans rather than explicit configuration classes means collaborators tend to be other full-fledged bean classes rather than methods of those used as higher order functions.
c
ah got it makes sense
r
I really like the idea of using methods as function parameters. I guess I was stuck in the Java Spring mindset and that hadn’t really occurred to me. However, I’d probably still use mocks for interaction testing, but it would certainly eliminate the need for stubs (using my definition of the distinction between mock and stub).