Spring Bootのユニットテストでセッションスコープのテストをしたいときに MockHttpSession
を使用することでモックデータを作成ができる。
MockHttpSession session = new MockHttpSession(); session.setAttribute("key", "value"); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session);