我的测试文件中有类似下面的内容
package stringutil
import (
"testing"
"gotest.tools/assert"
)
当我尝试测试它时,我得到了错误
$ go test github.com/user/stringutil
# github.com/user/stringutil
package github.com/user/stringutil (test)
imports gotest.tools/assert
imports gotest.tools/v3/assert/cmp: code in directory C:\Users\abc\go\src\gotest.tools\assert\cmp expects import "gotest.tools/assert/cmp"
FAIL github.com/user/stringutil [setup failed]
FAIL
然后我在导入中添加了“gotest.tools/assert/cmp”。
package stringutil
import (
"testing"
"gotest.tools/assert"
"gotest.tools/assert/cmp"
)
当我尝试测试它时,我得到了下一个错误
$ go test github.com/user/stringutil
# github.com/user/stringutil
package github.com/user/stringutil (test)
imports gotest.tools/assert
imports gotest.tools/v3/internal/format: code in directory C:\Users\abc\go\src\gotest.tools\internal\format expects import "gotest.tools/internal/format"
FAIL github.com/user/stringutil [setup failed]
FAIL
然后我在导入中添加了“gotest.tools/internal/format”
package stringutil
import (
"testing"
"gotest.tools/assert"
"gotest.tools/assert/cmp"
"gotest.tools/internal/format"
)
现在我在测试时遇到了另一个错误
$ go test github.com/user/stringutil
# github.com/user/stringutil
package github.com/user/stringutil (test)
imports gotest.tools/assert
imports gotest.tools/v3/assert/cmp
imports gotest.tools/v3/internal/format
imports gotest.tools/v3/internal/difflib: code in directory C:\Users\abc\go\src\gotest.tools\internal\difflib expects import "gotest.tools/internal/difflib"
FAIL github.com/user/stringutil [setup failed]
FAIL
然后我在导入中添加了“gotest.tools/internal/difflib”
package stringutil
import (
"testing"
"gotest.tools/assert"
"gotest.tools/assert/cmp"
"gotest.tools/internal/format"
"gotest.tools/internal/difflib"
)
如果我不使用 assert 我的测试有效
$ go test github.com/user/stringutil
ok github.com/user/stringutil 0.435s
看起来断言有问题?
慕哥9229398
相关分类