Unit testing 如何测试Go';s";“测试”;软件包功能?
我正在编写一个测试实用程序函数库,我希望它们能够自己测试 此类功能的一个示例是:Unit testing 如何测试Go';s";“测试”;软件包功能?,unit-testing,testing,go,Unit Testing,Testing,Go,我正在编写一个测试实用程序函数库,我希望它们能够自己测试 此类功能的一个示例是: func IsShwifty(t *testing.T, foo string) bool { result, err := bar.MyFunction(string) if err != nil { t.Error("Failed to get shwifty: " + foo, err) } return result == "shwifty" } 我想写一个Te
func IsShwifty(t *testing.T, foo string) bool {
result, err := bar.MyFunction(string)
if err != nil {
t.Error("Failed to get shwifty: " + foo, err)
}
return result == "shwifty"
}
我想写一个TestIsShwifty
,它输入一些东西,使MyFunction
返回一个错误,然后使t.error
。然后,我想让TestIsShwifty
通过如下内容:
func TestIsShwifty(t *testing.T) {
if doesError(t, IsShwifty(t)) == false {
t.Error("Oh know! We didn't error!")
}
}
这在围棋中可能吗 我想出来了
我只需要创建一个单独的testing.T
实例
func TestIsShwifty(t *testing.T) {
newT := testing.T{}
IsShwifty(newT)
if newT.Failed() == false {
t.Error("Test should have failed")
}
}
你遇到了哪些障碍?错误是什么?错误将破坏我的测试,但我希望我的测试在出现错误时通过。似乎您想要测试工具不支持的东西。我认为你不可能做到这一点。