Spring boot 我是否需要使用@SpringBootTest使用MockMvc测试不安全的端点,还是有其他方法?

Spring boot 我是否需要使用@SpringBootTest使用MockMvc测试不安全的端点,还是有其他方法?,spring-boot,spring-mvc,spring-security,spring-security-test,Spring Boot,Spring Mvc,Spring Security,Spring Security Test,我正在使用SpringSecurity开发一个Spring应用程序。 我的应用程序中有一些不安全的端点,我向所有想要访问它们的人公开这些端点。 现在,当我尝试使用@WebMvcTest测试“不安全端点”时,应用程序无法加载 原因:org.springframework.beans.factory.unsatifiedDependencyException:创建名为“securityConfiguration”的bean时出错 但是当使用整个上下文时,一切都很好 我的测试类的简单示例: 失败:

我正在使用SpringSecurity开发一个Spring应用程序。 我的应用程序中有一些不安全的端点,我向所有想要访问它们的人公开这些端点。 现在,当我尝试使用@WebMvcTest测试“不安全端点”时,应用程序无法加载

原因:org.springframework.beans.factory.unsatifiedDependencyException:创建名为“securityConfiguration”的bean时出错

  • 但是当使用整个上下文时,一切都很好
我的测试类的简单示例:
失败:

@WebMvcTest(controllers = SomeController.class)
class SomeControllerSearchTest {

    @MockBean
    SomeService someService;

    @Autowired
    MockMvc mockMvc;
    
    ...some tests

}
@SpringBootTest
@AutoConfigureMockMvc
@AutoConfigureTestDatabase
class SomeControllerSearchTest {

    @MockBean
    SomeService someService;

    @Autowired
    MockMvc mockMvc;

   ...some tests
}

有效:

@WebMvcTest(controllers = SomeController.class)
class SomeControllerSearchTest {

    @MockBean
    SomeService someService;

    @Autowired
    MockMvc mockMvc;
    
    ...some tests

}
@SpringBootTest
@AutoConfigureMockMvc
@AutoConfigureTestDatabase
class SomeControllerSearchTest {

    @MockBean
    SomeService someService;

    @Autowired
    MockMvc mockMvc;

   ...some tests
}

我试图让@WebMvcTest工作,但没有得到任何积极的结果:\

  • @导入(SecurityConfiguration.class)
  • @WebMvcTest(controllers=SomeController.class,includeFilters=@Filter(class=SecurityConfiguration.class)
  • 几乎没有其他尝试
我的问题是: 使用@WebMvcTest而不必使用整个应用程序上下文,测试我的不安全和安全端点的合适方法是什么