• goconvey


    从博主轩脉刃那里学到了一手goconvey,稍微记录一下,主要还是对方对于测试的理解和使用。

    测试要重cover而不是count,比如controller可以直接测试model和view,为什么要分开写。

    我个人习惯mock,但是博主反而提不要多mock,的确,我主要是对docker这块不熟悉,其实现在docker完美解决了之前了需要对数据库层面的测试问题,完全可以开一个docker跑你的测试。

    对于goconvey,就分享一下定制化断言。

    测试的主要函数原型

    func So(actual interface{}, assert assertion, expected ...interface{})
    type assertion func(actual interface{}, expected ...interface{}) string

    这里要注意不要定义success,否则就会出错。

    const (
       success                = ""
       needExactValues        = "This assertion requires exactly %d comparison values (you provided %d)."
       needNonEmptyCollection = "This assertion requires at least 1 comparison value (you provided 0)."
    )

    定制

    func ShouldCase(actual interface{}, expected ...interface{}) string {
        if actual == expected[0] {
            return ""
        } else {
            return "n"
        }
    }
    
    func TestAdd(t *testing.T) {
        Convey("相加", t, func() {
            So(Add(1, 3), ShouldCase, 4)
        })
    }

    当然大部分都是现成的不太需要我们定义,这就和junit差不多,还可以web界面。

    goconvey -port 8080

    这样我们就可以打开web,locahost:8080进行操作

    end

    一个没有高级趣味的人。 email:hushui502@gmail.com
  • 相关阅读:
    CentOS7安装MySql5.7
    环境变量配置
    Spring 注解
    MySQL
    常用命令
    Android Studio & IntelliJ IDEA常见问题与设置
    order by、group by、having的区别
    把WebStrom添加到右键菜单
    解决github访问速度慢的问题
    docker修改时区
  • 原文地址:https://www.cnblogs.com/CherryTab/p/12726283.html
Copyright © 2020-2023  润新知