title: Spring Boot: Disable security for Spring Boot Unit Test
body: <p>Spring Boot version: 2.0.4.RELEASE<br>
  For the Spring Boot Test below, the test returns an unwanted 401 response:<br><br>
      "401" status, "error": "unauthorized"<br><br>
  What is the best way to disable Spring Security for the tests?<br>
  I tried a adding a configuration "security.basic.enabled=false" property like so:<br><br></p>
  
  <pre><code>@SpringBootTest(&lt;br&gt;
      webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,&lt;br&gt;
      classes = TestApp.class,&lt;br&gt;
      properties = {
          "security.basic.enabled=false"
  })
  </code></pre>
  
  <p>And also adding this annotation to the class:<br></p>
  
  <pre><code>@AutoConfigureMockMvc(secure = false)
  </code></pre>
  
  <p>But unfortunately the test still returns a "401" unauthorized error code.<br>
  <br>
  Original test<br>
  <br></p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest(
  webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
  classes = App.class
  )
  
  public class ExampleTest{
  
  @Autowired
  public void setup(@LocalServerPort int port) {
      RestAssured.port = port;
  }
  
  @Test
  public voidtestMethod() {
  // This test code is not important to my question.     
  given().log().all().get("/resources").then().log().all().statusCode(HttpURLConnection.HTTP_BAD_REQUEST).body("error", equalTo("invalid_request")).body(not(containsString("error_reason")));
  }
  }
  </code></pre>
  
  <p>The class being unit tested is simple:<br><br></p>
  
  <pre><code>@SpringBootApplication
  @RestController
  public class App {
  @GetMapping("/resources")
  public String[] resources(
          @RequestParam("mandatory_param") String mandatory,
          @RequestParam("valid_param") @NotNull String validParam) {
      return new String[]{"1", "2"};
  }
  ...
  }
  </code></pre>
  
  <p>Does anyone know how to disable spring security for the test?
  Thank you</p>