我对Go非常陌生,我想知道关于如何测试Go Martini的Handler代码,有没有什么惯例/标准?
提前向您表示感谢!
发布于 2015-06-21 06:44:28
martini-contrib库有很多值得一看的现有代码:https://github.com/martini-contrib/secure/blob/master/secure_test.go
例如:
func Test_No_Config(t *testing.T) {
m := martini.Classic()
m.Use(Secure(Options{
// nothing here to configure
}))
m.Get("/foo", func() string {
return "bar"
})
res := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/foo", nil)
m.ServeHTTP(res, req)
expect(t, res.Code, http.StatusOK)
expect(t, res.Body.String(), `bar`)
}总而言之:
https://stackoverflow.com/questions/30958005
复制相似问题