I have a spring app and integration tests for this app. I would like to replace a bean with a mock bean.
My real bean looks like this
@Service
public class MyService {
}
and for testing I would like it to be replaced
@Service
public class TestMyService {
}
All I can think of is to use profiles for different services. For example:
@Service
@Profile("!test")
public class MyService implements IMyService {
}
@Service
@Profile("test")
public class TestMyService implements IMyService {
}
And then I autowire the bean like this
@Autowired
private IMyService myService;
Is there a better way?