我有一个用 An Authentication object was not found in the SecurityContext
注释的UserRepository。当我执行mockMvc请求时,模拟的身份验证按预期工作。但之后的存储库访问失败了:
@WithMockUser(roles = "ADMIN")
def "access repo with security"() {
expect:
mockMvc.perform(get("/"))
employeeRepository.deleteAll()
employeeRepository.count() == 0
}
这是我失败的测试:
@WithMockUser(roles = "ADMIN")
def "access repo with security"() {
expect:
employeeRepository.deleteAll()
employeeRepository.count() == 0
}
此测试(没有mockMvc)成功:
calloc
任何人都可以解释一下,为什么它在mockMvc之后失败了?