我正在嘗試解決Go 中的Karate Chop kata 作為練習(xí),并在我的測試用例中遇到了這個編譯器錯誤:調(diào)用 this.T.common.Fail 的參數(shù)太多我testing.T用額外的方法包裝成一個結(jié)構(gòu)體,作為一個匿名結(jié)構(gòu)體字段:package mainimport ( "fmt" "testing")type assertions struct { *testing.T}func (this assertions) assert_equal(expected int, actual int) { if (expected != actual) { this.Fail(fmt.Sprintf("Failed asserting that %v is %v", actual, expected)); }}func TestChop(t *testing.T) { test := assertions{t} test.assert_equal(-1, Chop(3, []int{})) test.assert_equal(-1, Chop(3, []int{1})) ...}我希望this.Fail調(diào)用帶有字符串參數(shù)Fail()的匿名testing.T結(jié)構(gòu)字段。為什么不是這種情況,它this.T.common.Fail來自哪里?我common在testing包文檔中找不到任何參考。
- 1 回答
- 0 關(guān)注
- 163 瀏覽
添加回答
舉報
0/150
提交
取消