#unittest.go
package unittest
// import
type box struct{
length int
width int
hight int
name string
}
func Newbox() (*box){
return &box{}
}
func (v *box) SetName(name string){
v.name = name
}
func (v *box) SetSize(l,w,h int){
v.length = l
v.width = w
v.hight = h
}
func (v *box) GetVolume() (int){
return (v.length*v.width*v.hight)
}
func (v *box) GetName() (string){
return v.name
}
#unittest_test.go
package unittest
import (
"fmt"
"testing"
)
func TestGetName(t *testing.T) {
b := Newbox()
b.SetName("aaaaa")
if b.name == "aaaaa" {
#t.Logf与Printf用法相同 失败显示 -v成功也显示
t.Logf("the rectangular name's result is ok")
}
else{
#t.FailNow()将当前测试标识为失败并停止执行该测试
#Fatalf 相当于在调用 Logf 之后调用 FailNow
t.Fatalf("the rectangular name's result is failed")
}
}