前面我们介绍了golang测试框架里面的testify, 下面让了解一下另一个用的也比较多的断言框架goconvey。
goconvey是一个支持golang的单元测试框架,能够自动监控文件修改并启动测试,并可以将测试结果实时输出到web界面,goconvey提供了丰富的断言简化测试用例的编写。
github地址:https://github.com/smartystreets/goconvey
以下是官方列举的goconvey的几个特性:
相比较于testify,goconvey可以功能较为聚焦,自动化做的非常赞,测试报告也是非常的专业。接下来让我们具体看一下如何使用goconvey框架吧。
go get github.com/smartystreets/goconvey
GoConvey "Given-when-then"(如果-当-推断)的模式, 非常符合我们人的正常理解逻辑。
package package_name
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestSpec(t *testing.T) {
// Only pass t into top-level Convey calls
Convey("Given some integer with a starting value", t, func() {
x := 1
Convey("When the integer is incremented", func() {
x++
Convey("The value should be greater by one", func() {
So(x, ShouldEqual, 2)
})
})
})
}
$ $GOPATH/bin/goconvey
通过http://localhost:8080可以查看测试结果,如果测试代码有做修改,面板会自动更新。
更多请参考官方iwiki:https://github.com/smartystreets/goconvey/wiki/Documentation
本文系外文翻译,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系外文翻译,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。