Announcement Announcement Module
Collapse
No announcement yet.
Mock services in spring-test-mvc Autowired.NO! Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mock services in spring-test-mvc Autowired.NO!

    I am trying to use spring-mvc-test framework to test my controller (name it MainController).
    MainController has injected one service (OuterService) witch i want to mock in standolone test configuration. That service conteins another service as autowired field.

    For my tests i am using context in java class witch looks like:

    Code:
    @Configuration
    public class MainControllerTestContext {
    
      @Bean
      public MainController mainController(){
        return new MainController();
      }
    
      @Bean(autowire=Autowire.NO)
      public OuterService outerService(){
        return Mockito.mock(OuterService.class);
      }
    
    }
    When i fire up my tests failed with exceptions like:
    Code:
    Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.mcg.services.dao.InnerService com.mcg.services.OuterService.innerService;
    When i am using interfaces for that services it is everything ok. But i do not want to (I will have one and only one service with interface like this, so implementing interfece is useless).

    How to solve that problem... ?

    Thanks in advance!
    Last edited by damian0o; Oct 4th, 2012, 02:39 AM.
Working...
X