【发布时间】:2016-06-05 22:22:20
【问题描述】:
我对 Spring 4 MVC 应用程序的 DAO 层进行了一些单元测试。然后我将 Spring Security 添加到我的控制器中的某些方法以及它们使用的 DAO 中。
我想出了如何使 @WithMockUser 注释在控制器测试中起作用,但我对 DAO 测试感到困惑。我在每个 dao 测试中遇到的例外是:
java.lang.IllegalStateException: Failed to load ApplicationContext
....
Caused by: java.lang.IllegalArgumentException: An AuthenticationManager is required
我在 DaoTest 开始时有这些注释:
@TestExecutionListeners({ WithSecurityContextTestExecutionListener.class })
@ContextConfiguration(classes = DaoConfig.class)
@ContextConfiguration 与实际代码相同;我有建议让它与众不同,但没有什么具体的。我该如何解开这个?我也希望有一种方法可以在不使用 org.springframework.web.* 或 org.springframework.test.web.* 类的情况下做到这一点,因为这应该在整个网络层的“下方”。
【问题讨论】:
标签: java spring unit-testing dao