SpringSecurity实战测试如何进行?
- 内容介绍
- 文章标签
- 相关推荐
本文共计866个文字,预计阅读时间需要4分钟。
引用测试题管理系统,采用Spring Security模块进行安全模块使用,代码从原华软库移植,移植过程中发现原测试题编写存在问题,在新系统中对安全模块进行了重构。+Spring 测试 + 添加 @SpringBootTest
引言
试题管理系统的安全模块使用Spring Security,代码从原华软仓库移植,在移植的过程中,发现原测试编写的不好,遂在新系统中对安全模块测试进行了重构。
Spring 测试
添加@SpringBootTest注解,意为这是一个基于SpringBoot的单元测试。
SpringBoot在官方的Guide中提供了多种测试方式。
@SpringBootTest注解中的webEnvironment属性可以配置测试环境,默认为MOCK环境。
/** * The type of web environment to create when applicable. Defaults to * {@link WebEnvironment#MOCK}. * @return the type of web environment */ WebEnvironment webEnvironment() default WebEnvironment.MOCK;
模拟环境测试
启用Spring Security后,单元测试中对api的测试会被Spring Security的Filter进行拦截,所以测试之前需要进行用户登录操作。
本文共计866个文字,预计阅读时间需要4分钟。
引用测试题管理系统,采用Spring Security模块进行安全模块使用,代码从原华软库移植,移植过程中发现原测试题编写存在问题,在新系统中对安全模块进行了重构。+Spring 测试 + 添加 @SpringBootTest
引言
试题管理系统的安全模块使用Spring Security,代码从原华软仓库移植,在移植的过程中,发现原测试编写的不好,遂在新系统中对安全模块测试进行了重构。
Spring 测试
添加@SpringBootTest注解,意为这是一个基于SpringBoot的单元测试。
SpringBoot在官方的Guide中提供了多种测试方式。
@SpringBootTest注解中的webEnvironment属性可以配置测试环境,默认为MOCK环境。
/** * The type of web environment to create when applicable. Defaults to * {@link WebEnvironment#MOCK}. * @return the type of web environment */ WebEnvironment webEnvironment() default WebEnvironment.MOCK;
模拟环境测试
启用Spring Security后,单元测试中对api的测试会被Spring Security的Filter进行拦截,所以测试之前需要进行用户登录操作。

