-
Hi, I'm using Echo framework and unable to get the code coverage from go test command (with options of course ). This test is not in the same package from its functional package. I.e : the main functional package is Is it this package is currently unable to produce code coverage, or actually I'm doing wrong on my test ? This is sample of my project structure :
This is the sample of user_test.go : package tests
import (
"net/http"
"net/http/httptest"
"testing"
"myapp/router"
"github.com/gavv/httpexpect"
)
func TestGetUsers(t *testing.T) {
RebuildData()
// This is actually the instance of Echo router
handler := router.New()
// run server using httptest
server := httptest.NewServer(handler)
defer server.Close()
// create httpexpect instance
e := httpexpect.New(t, server.URL)
// without query string
obj := e.GET("/users").
Expect().
Status(http.StatusOK).JSON().Object()
obj.Keys().Contains("data")
obj.Value("data").Array().Element(0).Object()
// with rp & p set
obj = e.GET("/users").WithQuery("rp", "2").WithQuery("p", "2").
Expect().
Status(http.StatusOK).JSON().Object()
obj.Keys().Contains("data")
obj.Value("data").Array().Element(0).Object().Value("id").Equal(3)
// with filter name
obj = e.GET("/users").WithQuery("name", "iman").
Expect().
Status(http.StatusOK).JSON().Object()
obj.Keys().Contains("data")
obj.Value("data").Array().Element(0).Object().Value("name").Equal("iman")
} This is the command to produce coverage > go test tests/*_test.go -cover -coverprofile=coverage.out |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Sorry, its not related with this repo but the Go it self. Coverage cannot be reported within Go 1.10, you need to upgrade to 1.11 or down grade to 1.9. |
Beta Was this translation helpful? Give feedback.
Sorry, its not related with this repo but the Go it self.
Coverage cannot be reported within Go 1.10, you need to upgrade to 1.11 or down grade to 1.9.
golang/go#25093