springmockk icon indicating copy to clipboard operation
springmockk copied to clipboard

How to use @SpykBeans and @MockkBeans?

Open dAnjou opened this issue 11 months ago • 0 comments

Hi,

in my Spring Boot + Kotlin codebase I have a @RestController asking for various dependencies via constructor injection. Most of these dependencies in turn ask for other dependencies themselves. So far nothing unusual, I guess.

Now I'd like to write a few tests where I use some of the dependencies but about others I don't care so much.

But I still need to make them available as Beans.

So, I've been @SpykBeaning each individual one of those I don't care about:

@SpykBean
private lateinit var lorem: Lorem
@SpykBean
private lateinit var ipsum: Ipsum
@SpykBean
private lateinit var dolor: Dolor

But I thought maybe there is an easier/shorter way, so I found @SpykBeans (plural):

@SpykBeans(
    SpykBean(Lorem::class),
    SpykBean(Ipsum::class),
    SpykBean(Dolor::class)
)
internal class irrelevantComponents

The former works, the latter doesn't, Spring can't find the beans. Am I using this wrong?

🙏

dAnjou avatar Mar 13 '24 13:03 dAnjou