mod*_*ler 4 java testing spring
我有一个需要登录的 Web 应用程序。登录成功后,会加载很多会话属性,后续其他网页的导航需要用到这些属性。
我正在使用 Spring 测试框架 4.12 和 MockMVC 测试这个 Web 应用程序。
如何在登录页面访问后链接第二个页面访问操作?就像是:
mockMvc.perform(post("/login").session(session).param("username", "Jack").param("password","Jack'sPassword"))
.perform(get("/anotherPage")).andExpect(/*some session attribute are successfully loaded*/)
Run Code Online (Sandbox Code Playgroud)
小智 6
您可以使用 andDo 方法来链接您的请求
mockMvc.perform(post("/login").session(session)
.param("username","Jack").param("password","Jack'sPassword"))
//Expectations on the first request
.andExpect(status().ok())
//Then chain the request
.andDo(
result -> mockMvc.perform(get("/anotherPage")).andExpect(/*some session attribute are successfully loaded*
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3708 次 |
| 最近记录: |