为了账号安全,请及时绑定邮箱和手机立即绑定

使用 testing.T 作为匿名结构字段:

使用 testing.T 作为匿名结构字段:

Go
富国沪深 2021-11-01 16:31:44
我正在尝试解决Go 中的Karate Chop kata 作为练习,并在我的测试用例中遇到了这个编译器错误:调用 this.T.common.Fail 的参数太多我testing.T用额外的方法包装成一个结构体,作为一个匿名结构体字段: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调用带有字符串参数Fail()的匿名testing.T结构字段。为什么不是这种情况,它this.T.common.Fail来自哪里?我common在testing包文档中找不到任何参考。
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 168 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号