> In my actual test, my bean is loaded up with spring
> component scan (most of the tests that use this are integration tests)

Actually I would not advice putting Mockito mocks into integration
tests, as the latter approach makes your test hard to maintain and
control.

But of course you can configure your Spring context scanning to pick
the right bean depending on the execution context. One way to achieve
this is via Spring Profiles [1]. The easiest way to put Mockito mock
into your Spring context is via Spring Java Configuration as
@Configurations are detected by the Spring classpath scanning:

@Configuration
public class MockConfiguration {

  @Bean
  public MyComponent bean() {
    return Mockito.mock(MyComponent.class);
  }

}

You can also consider using Arquillian [2] for composing isolated test
classpath which will contain your MockConfiguration (if you don't like
or can't use Spring Profiles). Arquillian is a fine piece of software
and I will introduce official Camel and ServiceMix support for it in
the future. In the meantime you can benefit even from vanilla
Arquillian setup.

Word of advice - if you plan to introduce Mocks into your tests, try
to do it on the registry [3] level (Spring in your particular case),
not by hacking the routes with AOP or interceptors. This will make
your tests much easier to maintain. Also tests running routes not
affected by interceptors are more likely to reflect your production
environment.

[1] http://blog.springsource.org/2011/02/14/spring-3-1-m1-introducing-profile
[2] http://arquillian.org
[3] http://camel.apache.org/registry.html

--
Henryk Konsek
http://henryk-konsek.blogspot.com

Reply via email to