2

I want write an integration test but with one minor restriction. I got a TimeSourceBean that I want to mock out. This TimeSourceBean is used several times deep in the application. (no way to do this with reflection)

Everything is done by autowire.

I think I could load in my test an additional XML with an implementation I like to have. see: here!

But really nice would be when I can create my mock TimeSourceBean in the test itself and register it (replace the original bean) to the context

=> so before I start the test, I create the mock and register my bean like this:

context.registerBean(timeSourceBeanMockVersion);

Any ideas if this is possible?

Community
  • 1
  • 1
user286974
  • 111
  • 1
  • 1
  • 12

1 Answers1

0

You can add an other bean/class that implement the same interface (hopefully you use them), and mark this other bean class as @Primary.

But then you need to make sure that this primary bean is only loaded in the test cases you need them.

Ralph
  • 118,862
  • 56
  • 287
  • 383