我有如下的测试:如何在Go中编写测试作为一种方法?
package api_app
func (api *ApiResource) TestAuthenticate(t *testing.T) {
httpReq, _ := http.NewRequest("POST", "/login", nil)
req := restful.NewRequest(httpReq)
recorder := new(httptest.ResponseRecorder)
resp := restful.NewResponse(recorder)
api.Authenticate(req, resp)
if recorder.Code!= 404 {
t.Logf("Missing or wrong status code:%d", recorder.Code)
}
}
我想测试这个功能,但是当我做
go test api_app -v
测试从未梯级这一点。我明白那是因为我有这个功能的接收器。
有没有办法可以测试这个东西?
为什么不使用'http.Transport {}'? – KingRider 2016-08-24 13:09:52