Java Spring引导Http安全配置单元测试

Java Spring引导Http安全配置单元测试,java,spring,spring-boot,spring-security,Java,Spring,Spring Boot,Spring Security,在我的SpringBoot应用程序中,我有一个安全配置类,我正试图为它编写一个单元测试。这是我第一次这样做,所以我需要一些帮助。下面是代码。请提供一些帮助,我们将不胜感激。多谢各位 public class SecurityConfig extends WebSecurityConfigurerAdapter { private String id; private String pwd; private String role; @Autowired private Authenticat

在我的SpringBoot应用程序中,我有一个安全配置类,我正试图为它编写一个单元测试。这是我第一次这样做,所以我需要一些帮助。下面是代码。请提供一些帮助,我们将不胜感激。多谢各位

public class SecurityConfig extends WebSecurityConfigurerAdapter {

private String id;
private String pwd;
private String role;

@Autowired
private AuthenticationEntryPoint authEntryPoint;

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.csrf().disable().authorizeRequests()
            .anyRequest().authenticated()
            .and().httpBasic()
            .authenticationEntryPoint(authEntryPoint).and()
            .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);

    //This allows to view h2 console during development
    http.headers().frameOptions().sameOrigin();
}

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth.inMemoryAuthentication().
            withUser(id).
            password(pwd).
            roles(role);
}}

我不建议为配置类本身编写单元测试。一般来说,一个证明你的应用程序功能的集成测试(比如使用)效果最好


我意识到这不是你要的;然而,如果你看一看SpringSecurityRepo,你会发现他们也正是这样做的。i、 例如,为了测试他们的配置程序,.

你的问题是什么?我试图对这个类进行单元测试,但不确定如何进行