I want to get test coverage of a REST service written in Go. I am spawning REST service through a goroutine, then making HTTP requests using rest client, and reviewing the HTTP responses.
Tests are passing successfully but go test -cover
returns 0% test coverage.
Is there a way to get the actual test coverage of all the packages used inside the go lang REST service.
my test file: main_test.go
import (
"testing"
)
// Test started when the test binary is started. Only calls main.
func TestSystem(t *testing.T) {
go main() // Spinning up the go lang REST server in a separate go routine.
http.Post("https://localhost/do_something")
}
my output:
go test -cover main_test.go
ok command-line-arguments 0.668s coverage: 0.0% of statements