cancel
Showing results for 
Search instead for 
Did you mean: 

Replace one dependency with mock in integration test

Former Member
0 Kudos

I'm testing a class in an integration test which sends Events using the EventService bean. Since events are async and (seem) super hard to test I want to mock out the EventService dependency in my class. All other dependencies should be resolved as is.

I know that I can simply inject my class with the @Resource annotation und then use setter injection, however:

  • Mocks are not removed from the injected beans if you use setter injection. This causes other integration tests to fail if they reuse the same bean and expect a working version. I've resorted to injecting the original bean in the tearDown method to fix this.

  • I'd like to use constructor injection without defining explicit setters

Since Hybris customizes the test runner pretty heavily I'm at a loss how to integrate common Spring solutions like http://www.baeldung.com/injecting-mocks-in-spring

Accepted Solutions (0)

Answers (0)