0

I'm trying to generate test coverage for a package using the following commands.

go test -v ./models_test -coverpkg=./models -coverprofile=c.out && go tool cover -func=c.out

go test -v ./models_test -coverpkg=github.com/apremalal/go-test-cov/models -coverprofile=c.out && go tool cover -func=c.out

My repo structure is like below, and I'm executing commands indie folder

<go-test-cov>
 |
  -<models>
 |
  -<models-test>

I have hosted the code in github for easy referencing.

models/math.go

package models

func Add(x,y int) int{
  return x+y
}

models_test/math_test.go

package models_test

import (
    "testing"
  "github.com/apremalal/go-test-cov/models"
)

func TestAdd(t *testing.T) {
    total := models.Add(5, 5)
    if total != 10 {
       t.Errorf("Sum was incorrect, got: %d, want: %d.", total, 10)
    }
}

Each time I receive 0% test coverage though the tests get executed without errors.

I'm using go version go1.10.1 darwin/amd64. This method used to work in earlier go versions. Appreciate your help in finding out how to get this working with the latest go release.

Anuruddha
  • 3,187
  • 5
  • 31
  • 47

0 Answers0