如何将 https://github.com/go-test/deep 导入到您的 Golang 测试中
我是 Golang 新手。
我的 go 版本:1.17.8
尝试编写测试来比较 strcuts。 发现这个库可以显示哪些字段完全等效。 所以想到在 Reflect.DeepEqual 上使用它
,这是我的测试文件,
package main
import (
"os"
"testing"
"github.com/go-test/deep"
)
func TestDeepEqual(t *testing.T) {
os.Remove("_decktesting.txt")
d := newDeck()
d.saveToFile("_decktesting.txt")
l := newDeckFromFile("_decktesting.txt")
if diff := deep.Equal(d, l); diff != nil {
t.Error(diff)
}
}
这是尝试测试时的内容,
➜ go get
go-training/cards on develop [!] via
I'm new to Golang.
My go version: 1.17.8
Trying write tests to compare strcuts.
Found this lib can show you which fields exactly equivalent.
So thought of using it over reflect.DeepEqual
Here's my test go file,
package main
import (
"os"
"testing"
"github.com/go-test/deep"
)
func TestDeepEqual(t *testing.T) {
os.Remove("_decktesting.txt")
d := newDeck()
d.saveToFile("_decktesting.txt")
l := newDeckFromFile("_decktesting.txt")
if diff := deep.Equal(d, l); diff != nil {
t.Error(diff)
}
}
Here's what it says when try to test,
➜ go get
go-training/cards on develop [!] via ???? v1.17.8
➜ go test
# go-training/cards
deck_test.go:7:2: cannot find package "github.com/go-test/deep" in any of:
/usr/local/go/src/github.com/go-test/deep (from $GOROOT)
/Users/ssamarasin/go/src/github.com/go-test/deep (from $GOPATH)
FAIL go-training/cards [setup failed]
go-training/cards on develop [!] via ???? v1.17.8
➜ go install github.com/go-test/deep@latest
package github.com/go-test/deep is not a main package
Can someone please explain how I can use this lib to compare my structs?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)