How to get all route handler for testing #439

appleboy opened this Issue Mar 31, 2016 · 5 comments


None yet

2 participants


Hi @labstack @Gouthamve

According to #293.

I want to get echo all router handler for testing.

package main

import (


func main() {
    e := echo.New()

    e.Get("/", hello())

    router := e.Router()

    req, _ := http.NewRequest("GET", "/", nil)
    w := httptest.NewRecorder()

    router.ServeHTTP(w, req)

// Handler
func hello() echo.HandlerFunc {
    return func(c echo.Context) error {
        return c.String(http.StatusOK, "Hello World")

I got the following error message:

./a.go:21: router.ServeHTTP undefined (type *echo.Router has no field or method ServeHTTP)

I don't want to use the following way like this.

rq := test.NewRequest(rc.Method, rc.Path, strings.NewReader(rc.Body))
rec := test.NewResponseRecorder()
e.ServeHTTP(rq, rec)


vishr commented Mar 31, 2016

Things have changed in v2, it doesn't directly accept standard http.Request and http.ResponseWriter. This has been done to provide support for fasthttp server. What exactly are you trying to achieve?


Hi @vishr

I create the gofight project for API testing. I want to testing all golang route framework using standard http.Request and http.ResponseWriter.

func TestEchoHelloWorld(t *testing.T) {
  r := mocha.New()

    RunEcho(EchoEngine(), func(r gofight.EchoHttpResponse, rq gofight.EchoHttpRequest) {
      assert.Equal(t, "Hello World", r.Body.String())
      assert.Equal(t, http.StatusOK, r.Status())

I need integrate RunEcho func with Run func

Thanks for your reply quickly.

vishr commented Mar 31, 2016

You should use engine.Request and engine.Response for testing. What's the problem with test package?



I want uniform Interface for request and response. If I want to test response status code, you must call r.status() not r.Code in echo framework.

@appleboy appleboy referenced this issue in appleboy/gofight Nov 16, 2016

Support echo v3.0.0 #40


Update gofight to v2.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment