```
package main
import (
"testing"
)
type wallet struct {
bitcoin int
}
func TestTb(t *testing.T) {
wa:=wallet{}
wa.deposit(10)
got:=wa.balance()
want:=10
if got!=want{
t.Errorf("got %d want %d",got,want)
}
}
func (w *wallet) deposit(v int) {
w.bitcoin+=v
}
func (w wallet) balance()int {
return w.bitcoin
}
```
运行结果
```
=== RUN TestTb
--- PASS: TestTb (0.00s)
PASS
```
按我的理解,wallet结构的balance方法,为值接收者,而不是指针接收者,按道理是返回0的
有疑问加站长微信联系(非本文作者)