goconvey简单介绍
goconvey测试框架
- 1.说明
- 2.github仓库
- 3.提供的断言以及方法
- 3.1 类型
- 3.1.1 判断是否
- 3.1.2 数值比较
- 3.1.3 包含内容
- 3.1.4 字符串
- 3.1.5 异常
- 3.1.6 类型
- 3.1.7 时间
- 3.2 提供的方法
- 3.3 用法
- 4.Web浏览
- 5.小结
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-reflectionSo(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 提供的方法
3.3 用法
简单来讲:引入包,启动Convey函数,剩下的就是调用So各种断言各种比较
示例:文件 example_one_test.go
package examplesimport ("testing". "github.com/smartystreets/goconvey/convey"
)func TestIntegerManipulation(t *testing.T) {t.Parallel()Convey("Given a starting integer value", t, func() {x := 42Convey("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框架。
goconvey简单介绍相关推荐
- 遗传算法的简单介绍以及模式定理的简单证明
遗传算法 遗传算法(Genetic Algorithm,GA),最早是由美国的John holland在20世纪70年代提出.算法通过模拟达尔文生物进化论的自然选择以及遗传学机理的生物进化过程来搜 ...
- 2021年大数据ELK(十八):Beats 简单介绍和FileBeat工作原理
全网最详细的大数据ELK文章系列,强烈建议收藏加关注! 新文章都已经列出历史文章目录,帮助大家回顾前面的知识重点. 目录 Beats 简单介绍和FileBeat工作原理 一.Beats 二.FileB ...
- 2021年大数据ELK(十五):Elasticsearch SQL简单介绍
全网最详细的大数据ELK文章系列,强烈建议收藏加关注! 新文章都已经列出历史文章目录,帮助大家回顾前面的知识重点. 目录 Elasticsearch SQL简单介绍 一.SQL与Elasticsear ...
- 2021年大数据ELK(二):Elasticsearch简单介绍
全网最详细的大数据ELK文章系列,强烈建议收藏加关注! 新文章都已经列出历史文章目录,帮助大家回顾前面的知识重点. 目录 系列历史文章 一.Elasticsearch简介 1.介绍 2.创始人 二.E ...
- iOS开发UI篇—多控制器和导航控制器简单介绍
iOS开发UI篇-多控制器和导航控制器简单介绍 一.多控制器 一个iOS的app很少只由一个控制器组成,除非这个app极其简单.当app中有多个控制器的时候,我们就需要对这些控制器进行管理 有多个vi ...
- 简单介绍一下R中的几种统计分布及常用模型
统计学上分布有很多,在R中基本都有描述.因能力有限,我们就挑选几个常用的.比较重要的简单介绍一下每种分布的定义,公式,以及在R中的展示. 统计分布每一种分布有四个函数:d――density(密度函数) ...
- LVS(Linux Virtual Server)三种负载均衡模型和十种调度的简单介绍
LVS(Linux Virtual Server)三种负载均衡模型和十种调度的简单介绍 LVS (Linux Virtual Server) LVS(Linux Virtual Server)其实就是 ...
- dubbo学习过程、使用经验分享及实现原理简单介绍
一.前言 部门去年年中开始各种改造,第一步是模块服务化,这边初选dubbo试用在一些非重要模块上,慢慢引入到一些稍微重要的功能上,半年时间,学习过程及线上使用遇到的些问题在此总结下. 整理这篇文章差不 ...
- iOS开发UI篇—UIWindow简单介绍
iOS开发UI篇-UIWindow简单介绍 一.简单介绍 UIWindow是一种特殊的UIView,通常在一个app中只会有一个UIWindow iOS程序启动完毕后,创建的第一个视图控件就是UIWi ...
最新文章
- Zookeeper的功能以及工作原理 (转自:http://www.cnblogs.com/felixzh/p/5869212.html)
- 汇编学习的安装DOSBOX及debug.exe教程
- maven构建可执行jar包
- WPF中在XAML中实现数据类型转换的两种方法
- 攻防世界 WEB 新手练习区 答题(1-12题解)
- C语言跨平台游戏开发
- 读 项亮《推荐系统实践》
- mybatis运行流程
- HBuilderX连接安卓模拟器
- html使table整体居中,如何让整个table表格居中?
- android画板过程分析,Android涂鸦画板原理详解——从初级到高级(二)
- 定时关机软件里的锁定计算机,怎么让电脑定时关机设置大全
- New UWP Community Toolkit - DeveloperTools
- 【html画板】网页画板绘画效果
- 面试经验之字节跳动暑期实习
- uniapp微信小程序富文本编辑器组件
- 2022!运势最牛X的三大星座!
- Mysql学习笔记(一):子查询与选择
- 搭建恋爱话术库一个月赚5w真实吗?
- 【夜曲编程Python数据分析】百题斩最后一题!!
热门文章
- android封装浏览器,android利用WebView实现浏览器的封装
- 如何将wrf文件转换成wmv格式
- 20几岁,你的存款有多少?
- 磁同步电机(pmsm,无位置传感器控制(扩张状态观测器,超螺旋滑模,扩展卡尔曼滤波) 脉振高频注入(有方波和正弦两种)仿真模型。
- 3.2 Python 实例3-天天向上的力量
- 2020年大学计算机基础实验4,2020年新版大学计算机基础实验报告word操作word.docx...
- less基础知识总结
- 论文阅读:CTSpine1K:A Large-Scale Dataset for Spinal Vertebrae Segmentation in Computed Tomography
- 滴答清单windows_使用预升级清单免费更新到Windows 10头痛
- 优化企业会议解决方案