Disable security for unit tests with spring boot

前端 未结 8 1891
情话喂你
情话喂你 2020-11-27 19:16

I\'m trying to create a simple spring boot web project with security. I can launch the application fine and the security is working fine. However, I have some components t

相关标签:
8条回答
  • 2020-11-27 20:00

    Another way can be using @ActiveProfile. Create a separate yml file like application-nosecurity.yml, with below content:

    security:
      ignored: /**
    

    Now, annotate the Test class with @ActiveProfile("nosecurity") in which you don't want to use security like below:

    @RunWith(SpringRunner.class)
    @SpringBootTest(classes = Application.class)
    @ActiveProfile("nosecurity")
    public class BlaBlaTest {
    
       ## Your Test Code 
    
    }
    
    0 讨论(0)
  • 2020-11-27 20:07

    If your application wasn't web base but you need spring-security jar as dependency and you don't want spring-boot's auto configurations for spring-security while testing, you can add

    @SpringBootTest(webEnvironment = WebEnvironment.NONE)
    

    in your test class.

    0 讨论(0)
提交回复
热议问题