1

My abstract test needs to create a SpyBean of a defined class within the concrete implementation and I do not want the implementation or the "user" to have to add the @SpyBean annotation.

How can I programmatically create a SpyBean of a given Class without using the @SpyBean annotation?

Marian Klühspies
  • 15,824
  • 16
  • 93
  • 136
  • `Mockito.spy(…)` as a first step? – knittl Jan 10 '23 at 19:17
  • @knittl but does it create a bean that is known to the dependency injection? – Marian Klühspies Jan 10 '23 at 19:23
  • Yes, if it's used when creating the bean in the Spring test configuration (e.g. `@TestConfiguration` annotated class), but from the question I'm not sure if it solves your problem. Do you want non-abstract test classes to be able to provide the instance that should be a spied on and injected into the Spring context or just to avoid the non-abstract classes to know that a spy is used by the abstract class? – Jonasz Jan 11 '23 at 05:29

0 Answers0