我有一個@Aspect編織我所有的控制器操作方法的執行。它運行良好,我運行系統,但不是在單元測試()。我使用的的Mockito的junit在如下因素的方法:春天的AOP方面不工作使用Mockito
...
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("file:**/spring-context.xml")
@WebAppConfiguration
public class UserControllerTest {
private MockMvc mockMvc;
@Mock
private RoleService roleService;
@InjectMocks
private UserController userController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
...
mockMvc = MockMvcBuilders.standaloneSetup(userController).build();
}
...
}
一些@Test使用mockMvc.perform()
。
我的看點是:
@Pointcut("within(@org.springframework.stereotype.Controller *)")
public void controller() { }
@Pointcut("execution(* mypackage.controller.*Controller.*(..))")
public void methodPointcut() { }
@Around("controller() && methodPointcut()")
...
我有同樣的問題。我注意到,如果使用替代的''''''''''''''''''''''''''''而不是''standaloneSetup'',但在這種情況下,模擬不會被注入到控制器。我還沒有弄清楚如何讓這兩個工作 –