Golang软件包测试覆盖率在版本1.10.1中不起作用

Golang软件包测试覆盖率在版本1.10.1中不起作用,go,Go,我尝试使用以下命令为包生成测试覆盖率 go-test-v./models\u-test-coverpkg=./models-coverprofile=c.out&&go-tool-cover-func=c.out go-test-v./models\u-test-coverpkg=github.com/apremalal/go-test-cov/models-coverprofile=c.out和go-tool-cover-func=c.out 我的回购结构如下所示,我正在独立文件夹中执行命令

我尝试使用以下命令为包生成测试覆盖率

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

go-test-v./models\u-test-coverpkg=github.com/apremalal/go-test-cov/models-coverprofile=c.out和go-tool-cover-func=c.out

我的回购结构如下所示,我正在独立文件夹中执行命令

<go-test-cov>
 |
  -<models>
 |
  -<models-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)
    }
}
每次我收到0%的测试覆盖率,尽管测试执行时没有错误


我正在使用go版本
go1.10.1 darwin/amd64
。此方法用于早期go版本。感谢您帮助我们了解如何使用最新的go版本。请在问题中包含您的相关代码。@Flimzy更新了问题move
models\u test/math\u test。go
models/math\u test.go
@fhe我知道它在同一个包中工作。我想把测试用例放在包外以保持干净。可能的重复
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)
    }
}