blog-dovydasvenckus / blog

https://www.dovydasvenckus.dev
0 stars 0 forks source link

java/2019/05/05/mocking-spring-beans-with-spock/ #11

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Mocking Spring beans with Spock

Mocking Spring beans with Spock.

https://www.dovydasvenckus.dev/java/2019/05/05/mocking-spring-beans-with-spock/

farrukhnajmi commented 2 years ago

I am having this issue with use of SpringBeans with mocking and stubbing:

https://github.com/spockframework/spock/issues/1084

I am still struggling with how to inject the stub or mock impl for a spring Bean within the spring ApplicationContext which is created before the stub/mock are created.

dovydasvenckus commented 2 years ago

Hey @farrukhnajmi. I'm not sure if I understand your issue correctly.

Are you stubing outside of test specification file? Maybe stubing inside spec file could resolve your issue? Or you can try to use old way of using spring contex config explicitly https://www.dovydasvenckus.dev/java/2019/05/05/mocking-spring-beans-with-spock/#old-way?

I'm not really familiar with inner workings of spock framework. So I'm not sure if my tips will help you :)

harufu commented 1 month ago

Thanks you for this example. It was very helpful.