我有以下结构
type Server struct {
*http.Server
chain core.Blockchainer
coreServer *network.Server
}
及其相应的handler
func (s *Server) methodHandler(w http.ResponseWriter, req *Request, reqParams Params) {
.....
}
如何对handler
进行单元测试?
答案 0 :(得分:0)
上面的处理程序
func (s *Server) methodHandler(w http.ResponseWriter, req *Request, reqParams Params) {
.....
}
可以按照以下步骤进行测试
handler := http.HandlerFunc(s.methodHandler)
req := httptest.NewRequest(...)
w := httptest.NewRecorder()
handler(w, req)
resp := w.Result()
assert.Equal(t, expected, resp)