golang测试错误:无法在任何地方找到包”github.com/stretchr/testify/assert”。

huangapple go评论79阅读模式
英文:

golang test error: cannot find package "github.com/stretchr/testify/assert" in any of:

问题

我的翻译结果如下:

我的导入代码如下所示:

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

当我尝试运行 go test 时,我收到以下错误信息:

cannot find package "github.com/stretchr/testify/assert" in any of:
	/Users/[username]/go/src/github.com/[group_name]/[project_name]/vendor/github.com/stretchr/testify/assert (vendor tree)
	/usr/local/go/src/github.com/stretchr/testify/assert (from $GOROOT)
	/Users/[username]/go/src/github.com/stretchr/testify/assert (from $GOPATH)
FAIL	github.com/[group_name]/[project_name]/lib/briteverify [setup failed]

所以看起来问题出在最后一行,它说在 .../lib/briteverify 中找不到 github.com/stretchr/testify/assert。然而,我已经将其作为导入项,所以不知道为什么会出现这个错误。有什么想法吗?

英文:

My import looks like this below:

import (
"testing"

"github.com/stretchr/testify/assert"
)

when I try try running 'go test' I get the error message:

cannot find package "github.com/stretchr/testify/assert" in any of:
/Users/[username]/go/src/github.com/[group_name]/[project_name]/vendor/github.com/stretchr/testify/assert (vendor tree)
/usr/local/go/src/github.com/stretchr/testify/assert (from $GOROOT)
/Users/[username]/go/src/github.com/stretchr/testify/assert (from $GOPATH)
FAIL	github.com/[group_name]/[project_name]/lib/briteverify [setup failed]

So it appears the last line is the issue, where it says in .../lib/briteverify it cannot find github.com/stretchr/testify/assert. However, I have this as an import so I don't know why it would throw this error. Any thoughts?

答案1

得分: 17

你需要导入该包并运行go get github.com/package/path来安装该包。

英文:

Moving the answer here for others in the future.

You need to both import the package and run go get github.com/package/path to install the package.

huangapple
  • 本文由 发表于 2017年2月16日 00:11:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/42254513.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定