{"action":"created","issue":{"url":"https://api.github.com/repos/astaxie/beego/issues/1561","labels_url":"https://api.github.com/repos/astaxie/beego/issues/1561/labels{/name}","comments_url":"https://api.github.com/repos/astaxie/beego/issues/1561/comments","events_url":"https://api.github.com/repos/astaxie/beego/issues/1561/events","html_url":"https://github.com/astaxie/beego/issues/1561","id":126364385,"number":1561,"title":"单元测试问题","user":{"login":"ltt1987","id":8955240,"avatar_url":"https://avatars.githubusercontent.com/u/8955240?v=3","gravatar_id":"","url":"https://api.github.com/users/ltt1987","html_url":"https://github.com/ltt1987","followers_url":"https://api.github.com/users/ltt1987/followers","following_url":"https://api.github.com/users/ltt1987/following{/other_user}","gists_url":"https://api.github.com/users/ltt1987/gists{/gist_id}","starred_url":"https://api.github.com/users/ltt1987/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ltt1987/subscriptions","organizations_url":"https://api.github.com/users/ltt1987/orgs","repos_url":"https://api.github.com/users/ltt1987/repos","events_url":"https://api.github.com/users/ltt1987/events{/privacy}","received_events_url":"https://api.github.com/users/ltt1987/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-13T08:02:01Z","updated_at":"2016-01-13T08:08:53Z","closed_at":null,"body":"你好，我再使用beego和goconvey做单元测试的时候，出现如下问题，路由设置如下：\r\n```\r\nbeego.Router(\"/token\", &controllers.AuthController{}, \"post:RequestToken\")\r\nbeego.Router(\"/sayhi\", &controllers.AuthController{}, \"post:SayHi\")\r\n```\r\ncontroller里面的实现很简单，下面是SayHi的实现：\r\n```\r\nfunc (this *AuthController) SayHi() {\r\n\tthis.Data[\"json\"] = \"hi\"\r\n\tthis.ServeJson()\r\n}\r\n```\r\n下面是testing里面的部分内容：\r\n```\r\nfunc init() {\r\n\t_, file, _, _ := runtime.Caller(1)\r\n\tapppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, \"..\"+string(filepath.Separator))))\r\n\tbeego.TestBeegoInit(apppath)\r\n}\r\n\r\nfunc makeHttpRequest(method string, url string, body io.Reader) (req *http.Request, write *httptest.ResponseRecorder, err error) {\r\n\tr, e := http.NewRequest(method, url, body)\r\n\tr.Header.Set(\"Content-Type\", \"application/x-www-form-urlencoded\")\r\n\tw := httptest.NewRecorder()\r\n\treturn r, w, e\r\n}\r\n\r\nfunc TestSayHi(t *testing.T) {\r\n\tConvey(\"Say Hi\", t, func() {\r\n\t\tr, w, _ := makeHttpRequest(\"POST\", \"/sayhi\", nil)\r\n\t\tbeego.BeeApp.Handlers.ServeHTTP(w, r)\r\n\r\n\t\tSo(w.Body.String(), ShouldContainSubstring, \"hi\")\r\n\t})\r\n}\r\n```\r\n我做`RequestToken`的各种测试均正常，但是给这个最简单的sayhi做测试的时候，就会报错，不通过，错误信息如下，但是通过web可以正常访问，单独写个go程序也能通过，就是在beego里面做测试的时候才出错的。\r\n```\r\nTestSayHi\r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:879] [C] the request url is  /sayhi \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:880] [C] Handler crashed with error runtime error: invalid memory address or nil pointer dereference \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /usr/local/go/src/runtime/asm_amd64.s:437 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /usr/local/go/src/runtime/panic.go:423 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /usr/local/go/src/io/ioutil/ioutil.go:30 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /usr/local/go/src/runtime/asm_amd64.s:437 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /usr/local/go/src/runtime/panic.go:423 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /usr/local/go/src/runtime/panic.go:42 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /usr/local/go/src/runtime/sigpanic_unix.go:24 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /usr/local/go/src/bytes/buffer.go:173 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /usr/local/go/src/io/ioutil/ioutil.go:33 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /usr/local/go/src/io/ioutil/ioutil.go:42 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /Users/paul/go/src/github.com/astaxie/beego/context/input.go:295 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /Users/paul/go/src/github.com/astaxie/beego/router.go:668 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /Users/paul/go/src/authenticate_server/tests/auth_test.go:37 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /Users/paul/go/src/github.com/smartystreets/goconvey/convey/discovery.go:80 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /Users/paul/go/src/github.com/smartystreets/goconvey/convey/context.go:261 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /Users/paul/go/src/github.com/smartystreets/goconvey/convey/context.go:110 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /Users/paul/go/src/github.com/jtolds/gls/stack_tags.go:70 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /Users/paul/go/src/github.com/jtolds/gls/stack_tags.go:21 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /Users/paul/go/src/github.com/jtolds/gls/stack_tags.go:18 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /Users/paul/go/src/github.com/jtolds/gls/context.go:98 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /Users/paul/go/src/github.com/smartystreets/goconvey/convey/context.go:113 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /Users/paul/go/src/github.com/smartystreets/goconvey/convey/doc.go:75 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /Users/paul/go/src/authenticate_server/tests/auth_test.go:40 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /usr/local/go/src/testing/testing.go:456 \r\n2016/01/13 15:46:28 \u001B[1;35m[router.go:886] [C] /usr/local/go/src/runtime/asm_amd64.s:1721\r\n```\r\n请教一下，是不是我的用法不对？请指正，谢谢！\r\n"},"comment":{"url":"https://api.github.com/repos/astaxie/beego/issues/comments/171211218","html_url":"https://github.com/astaxie/beego/issues/1561#issuecomment-171211218","issue_url":"https://api.github.com/repos/astaxie/beego/issues/1561","id":171211218,"user":{"login":"astaxie","id":233907,"avatar_url":"https://avatars.githubusercontent.com/u/233907?v=3","gravatar_id":"","url":"https://api.github.com/users/astaxie","html_url":"https://github.com/astaxie","followers_url":"https://api.github.com/users/astaxie/followers","following_url":"https://api.github.com/users/astaxie/following{/other_user}","gists_url":"https://api.github.com/users/astaxie/gists{/gist_id}","starred_url":"https://api.github.com/users/astaxie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astaxie/subscriptions","organizations_url":"https://api.github.com/users/astaxie/orgs","repos_url":"https://api.github.com/users/astaxie/repos","events_url":"https://api.github.com/users/astaxie/events{/privacy}","received_events_url":"https://api.github.com/users/astaxie/received_events","type":"User","site_admin":false},"created_at":"2016-01-13T08:08:53Z","updated_at":"2016-01-13T08:08:53Z","body":"please update the issue description to english. "}}