在go中,可以编写特定于结构的函数.
type one struct{}
func (o *one) fly() {}
Run Code Online (Sandbox Code Playgroud)
我的问题是如果有两个具有相同名称但指向不同结构的函数,如何测试函数.
type one struct{}
func (o *one) fly() {}
type two struct{}
func (t *two) fly() {}
Run Code Online (Sandbox Code Playgroud)
由于GO测试的格式是TestXxx(t*testing.T){}我不确定如何能够单独测试每个函数.谢谢
TestXxx只是一个命名惯例.Xxx可能是你想要的任何东西,但是Test(有Benchmark和Example)是必需的.因此,宣布2个测试功能 - TestOneFly而且TestTwoFly,就是这样.或者你可以测试两个TestFly,在一个测试中初始化两个结构.