Go:go test assert

By kcersing , 31 三月, 2020

测试包 地址

https://github.com/stretchr/testify

安装

go get -u github.com/stretchr/testify/assert

测试命令

go test -v -coverimport (
   "fmt"
   "github.com/stretchr/testify/assert"
   "testing"
)
func square(op int) int  {
   return op*op*op
}
func TestSquareWithAssert(t *testing.T)  {
   inputs :=[...]int{1,2,3}
   expected:=[...]int{1,4,9}
   for i:=0;i<len(inputs) ;i++  {
      ret:=square(inputs[i])
      assert.Equal(t,expected[i],ret)
   }
}


标签