我正在尝试使用Ring + Compojure + lib-noir进行Clojure web开发,但我不知道如何测试会话状态。
发布于 2014-08-02 10:29:21
我认为您可以在ring:https://github.com/ring-clojure/ring/blob/master/ring-core/test/ring/middleware/session/test/cookie.clj中模仿用于实际会话测试的样式。
只需创建一个cookie存储,然后对其进行读/写,并相应地断言处理程序响应。假设你也在使用lib-noir,也许这个例子更合适:https://github.com/noir-clojure/lib-noir/blob/master/test/noir/session_test.clj。
发布于 2015-12-18 00:45:37
如果您指的是单元测试,您可以使用binding
,它将为var创建新的绑定。
你可以查看一个很好的解释,可以在here找到。
使用lib-noir
进行单元测试的示例
(ns your.test.core
(:use [clojure.test])
(:require [noir.session :as s]))
(binding [s/*noir-session* (atom {})]
; store new sessions
(s/put! "xxxx" {:value "1234"})
(s/put! "my_session" {:value "abcdefg"})
; run tests
(is (= {:value "1234"} (s/get "xxxx")))
(is (= {:value "abcdefg"} (s/get "my_session"))))
你可以在这里查看noir.session
的source code。
https://stackoverflow.com/questions/15460449
复制相似问题