goconvey简单介绍

1.说明

goconvey是一款针对Golang的测试框架,可以管理和运行测试用例,同时提供了丰富的断言函数,并支持很多 Web 界面特性。

参考文档:https://www.cnblogs.com/feixiangmanon/p/11531328.html

安装:go get github.com/smartystreets/goconvey

2.github仓库

https://github.com/smartystreets/goconvey

3.提供的断言以及方法

3.1 类型

3.1.1 判断是否

func TestAssertionsAreAvailableFromConveyPackage(t *testing.T) {
    SetDefaultFailureMode(FailureContinues)
    defer SetDefaultFailureMode(FailureHalts)
 
    Convey("Equality assertions should be accessible", t, func() {
        thing1a := thing{a: "asdf"}
        thing1b := thing{a: "asdf"}
        thing2 := thing{a: "qwer"}
 
        So(1, ShouldEqual, 1)
        So(1, ShouldNotEqual, 2)
        So(1, ShouldAlmostEqual, 1.000000000000001)
        So(1, ShouldNotAlmostEqual, 2, 0.5)
        So(thing1a, ShouldResemble, thing1b)
        So(thing1a, ShouldNotResemble, thing2)
        So(&thing1a, ShouldPointTo, &thing1a)
        So(&thing1a, ShouldNotPointTo, &thing1b)
        So(nil, ShouldBeNil)
        So(1, ShouldNotBeNil)
        So(true, ShouldBeTrue)
        So(false, ShouldBeFalse)
        So(0, ShouldBeZeroValue)
        So(1, ShouldNotBeZeroValue)
    })
}

3.1.2 数值比较

Convey("Numeric comparison assertions should be accessible", t, func() {
        So(1, ShouldBeGreaterThan, 0)
        So(1, ShouldBeGreaterThanOrEqualTo, 1)
        So(1, ShouldBeLessThan, 2)
        So(1, ShouldBeLessThanOrEqualTo, 1)
        So(1, ShouldBeBetween, 0, 2)
        So(1, ShouldNotBeBetween, 2, 4)
        So(1, ShouldBeBetweenOrEqual, 1, 2)
        So(1, ShouldNotBeBetweenOrEqual, 2, 4)
    })

3.1.3 包含内容

Convey("Container assertions should be accessible", t, func() {
        So([]int{1, 2, 3}, ShouldContain, 2)
        So([]int{1, 2, 3}, ShouldNotContain, 4)
        So(map[int]int{1: 1, 2: 2, 3: 3}, ShouldContainKey, 2)
        So(map[int]int{1: 1, 2: 2, 3: 3}, ShouldNotContainKey, 4)
        So(1, ShouldBeIn, []int{1, 2, 3})
        So(4, ShouldNotBeIn, []int{1, 2, 3})
        So([]int{}, ShouldBeEmpty)
        So([]int{1}, ShouldNotBeEmpty)
        So([]int{1, 2}, ShouldHaveLength, 2)
    })

3.1.4 字符串

Convey("String assertions should be accessible", t, func() {
        So("asdf", ShouldStartWith, "a")
        So("asdf", ShouldNotStartWith, "z")
        So("asdf", ShouldEndWith, "df")
        So("asdf", ShouldNotEndWith, "as")
        So("", ShouldBeBlank)
        So("asdf", ShouldNotBeBlank)
        So("asdf", ShouldContainSubstring, "sd")
        So("asdf", ShouldNotContainSubstring, "af")
    })

3.1.5 异常

Convey("Panic recovery assertions should be accessible", t, func() {
        So(panics, ShouldPanic)
        So(func() {}, ShouldNotPanic)
        So(panics, ShouldPanicWith, "Goofy Gophers!")
        So(panics, ShouldNotPanicWith, "Guileless Gophers!")
    })

3.1.6 类型

Convey("Type-checking assertions should be accessible", t, func() {
 
        // NOTE: Values or pointers may be checked.  If a value is passed,
        // it will be cast as a pointer to the value to avoid cases where
        // the struct being tested takes pointer receivers. Go allows values
        // or pointers to be passed as receivers on methods with a value
        // receiver, but only pointers on methods with pointer receivers.
        // See:
        // http://golang.org/doc/effective_go.html#pointers_vs_values
        // http://golang.org/doc/effective_go.html#blank_implements
        // http://blog.golang.org/laws-of-reflection
 
        So(1, ShouldHaveSameTypeAs, 0)
        So(1, ShouldNotHaveSameTypeAs, "1")
 
        So(bytes.NewBufferString(""), ShouldImplement, (*io.Reader)(nil))
        So("string", ShouldNotImplement, (*io.Reader)(nil))
    })

3.1.7 时间

Convey("Time assertions should be accessible", t, func() {
        january1, _ := time.Parse(timeLayout, "2013-01-01 00:00")
        january2, _ := time.Parse(timeLayout, "2013-01-02 00:00")
        january3, _ := time.Parse(timeLayout, "2013-01-03 00:00")
        january4, _ := time.Parse(timeLayout, "2013-01-04 00:00")
        january5, _ := time.Parse(timeLayout, "2013-01-05 00:00")
        oneDay, _ := time.ParseDuration("24h0m0s")
 
        So(january1, ShouldHappenBefore, january4)
        So(january1, ShouldHappenOnOrBefore, january1)
        So(january2, ShouldHappenAfter, january1)
        So(january2, ShouldHappenOnOrAfter, january2)
        So(january3, ShouldHappenBetween, january2, january5)
        So(january3, ShouldHappenOnOrBetween, january3, january5)
        So(january1, ShouldNotHappenOnOrBetween, january2, january5)
        So(january2, ShouldHappenWithin, oneDay, january3)
        So(january5, ShouldNotHappenWithin, oneDay, january1)
        So([]time.Time{january1, january2}, ShouldBeChronological)
    })

3.2 提供的方法

goconvey提供的断言方法

3.3 用法

简单来讲:引入包,启动Convey函数,剩下的就是调用So各种断言各种比较

示例:文件 example_one_test.go

package examples
 
import (
    "testing"
    . "github.com/smartystreets/goconvey/convey"
)
 
func TestIntegerManipulation(t *testing.T) {
    t.Parallel()
 
    Convey("Given a starting integer value", t, func() {
        x := 42
 
        Convey("When incremented", func() {
            x++
 
            Convey("The value should be greater by one", func() {
                So(x, ShouldEqual, 43)
            })
            Convey("The value should NOT be what it used to be", func() {
                So(x, ShouldNotEqual, 42)
            })
        })
        Convey("When decremented", func() {
            x--
 
            Convey("The value should be lesser by one", func() {
                So(x, ShouldEqual, 41)
            })
            Convey("The value should NOT be what it used to be", func() {
                So(x, ShouldNotEqual, 42)
            })
        })
    })
}

4.Web浏览

参考:https://www.cnblogs.com/feixiangmanon/p/11531328.html

测试:进入测试文件目录,执行goconvey,访问浏览器界面展示测试结果。(默认127.0.0.1:8080)

5.小结

goconvey 提供了丰富的断言函数,并支持很多 Web 界面特性。但是作用有限,没有提供mock相关功能,因此通常搭配其他mock框架使用。后面将介绍其中一种mock框架,gomonkey框架。

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: To convey means to communicate, express, or transfer a message, idea, feeling, or information from one person or entity to another. It involves transmitting or delivering something from one place, person, or point to another. Conveying can be done through various means, such as speaking, writing, body language, gestures, signals, or other forms of communication. The main goal of conveying is to make sure that the intended message is accurately and clearly understood by the receiver. ### 回答2: "传达"是指通过言语、文字、行为或其他交流方式将信息、想法、情感等传递给他人的过程。在日常生活中,我们经常需要进行沟通和交流,以便与他人建立联系、分享信息和观点,并理解他人的意图和想法。 "传达"可以包括口头、书面和非语言的方式。口头传达是指使用口头语言进行交流,如谈话、演讲、讨论等。书面传达是指使用文字和符号来表达想法、观点和信息,如书写、邮件、报告等。非语言传达则是通过身体语言、表情、姿势、手势、肢体动作和声音等方式来传递信息和情感。 传达的目的是为了让对方理解并接受所传递的信息。为了达到这个目的,传达需要具备清晰的表达能力、有效的沟通技巧和适当的语言、声音和非语言表达方式。此外,传达还需要适应不同的语言和文化背景,避免产生误解和歧义。 传达的重要性在各个领域中都得到体现。在商业上,有效的传达可以帮助提升销售业绩、建立良好的客户关系和实现业务目标。在教育中,传达有助于教师与学生之间的知识传递与理解。在社交交往中,传达可以帮助人们建立亲密的关系和良好的人际关系。 总而言之,"传达"是指将信息、想法和情感传递给他人的过程,通过适当的语言、声音和非语言表达方式,以确保对方准确理解并接受所传递的信息。传达在各个领域中都具有重要的作用,是人际交往和社会互动的基础。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值