How to mock custom UserServiceDetails in SpringSecurity Bean for unit-testing?

前端 未结 1 1325
梦毁少年i
梦毁少年i 2021-01-07 04:21

I have Spring Boot application with basic auth enabled. UserServiceDetails consumed from DB. For the unit-testing purpose, I want to mock it, so th

相关标签:
1条回答
  • 2021-01-07 04:44

    I think you should use @Profile, UserDetailesService is an interface creates two implementation of UserDetailesService, one for test and another for the rest of the case

    @Component
    @Profile("test")
    public class UserDetailesServiceTestImpl implements UserDetailesService{
    
    
    }
    
    @Component
    @Profile("!test")
    public class UserDetailesServiceImpl implements UserDetailesService{
    
    
    }
    
    0 讨论(0)
提交回复
热议问题