Spring 引导和 RestAssured 中的模拟会话

Mock Session in Spring Boot and RestAssured

我有一个 Web 应用程序,运行 Spring Boot.现在我必须使用 Rest Assured 编写测试。 但是,对于 运行 其中一些,我必须在服务器上进行身份验证。服务器使用 google oauth 身份验证。有什么办法可以放心模拟session吗? 文档对此没有太多说明,那里介绍的方法也无济于事。

when()
      .sessionId("id here")

在服务器端,我使用的是带有 userId 参数的 HttpSession。

我找到了解决办法。 RestAssured(自 3.0.0 起)与 MockMvc 集成,可以通过调用类似

的方式实现会话模拟
given().sessionAttr("name", value)