Unit testing

We would not want to use security for our unit tests. The following code snippet shows how we can disable security for the unit test:

   @RunWith(SpringRunner.class)   @WebMvcTest(value = TodoController.class, secure = false)   public class TodoControllerTest {

The key part is the secure = false parameter on the WebMvcTest annotation. This will disable Spring Security for the unit test.

Get Mastering Spring 5.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.