当前位置: 首页 > news >正文

贵州建设监理协会网站进不了重庆正云环保工程有限公司网页制作

贵州建设监理协会网站进不了,重庆正云环保工程有限公司网页制作,网站建设西班牙语,ui设计工作室一、尽量用Convey将所有测试用例的Convey汇总 用Convey嵌套的方法#xff0c;将所有测试用例的Convey用一个大的Convey包裹起来#xff0c;每个测试函数下只有一个大的Convey。比如下面的示例代码#xff1a; import (testing. github.com/smartystreet…一、尽量用Convey将所有测试用例的Convey汇总 用Convey嵌套的方法将所有测试用例的Convey用一个大的Convey包裹起来每个测试函数下只有一个大的Convey。比如下面的示例代码 import (testing. github.com/smartystreets/goconvey/convey )func TestStringSliceEqual(t *testing.T) {Convey(TestStringSliceEqual, t, func() {Convey(should return true when a ! nil b ! nil, func() {a : []string{hello, goconvey}b : []string{hello, goconvey}So(StringSliceEqual(a, b), ShouldBeTrue)})Convey(should return true when a nil b nil, func() {So(StringSliceEqual(nil, nil), ShouldBeTrue)})Convey(should return false when a nil b ! nil, func() {a : []string(nil)b : []string{}So(StringSliceEqual(a, b), ShouldBeFalse)})Convey(should return false when a ! nil b ! nil, func() {a : []string{hello, world}b : []string{hello, goconvey}So(StringSliceEqual(a, b), ShouldBeFalse)})}) } 这样做的好处是看单测结果更为清晰直观 RUN TestStringSliceEqualTestStringSliceEqual should return true when a ! nil b ! nil ✔should return true when a nil b nil ✔should return false when a nil b ! nil ✔should return false when a ! nil b ! nil ✔4 total assertions--- PASS: TestStringSliceEqual (0.00s) PASS ok infra/alg 0.006s二、用GWT结构来描述复杂的测试用例 GWT结构嵌套了三层Convey最外层是Given层用来给定测试用例需要的数据中间一层是When层用来执行被测试的函数方法得到result最内层是Then层用So来对result进行断言看结果是否满足期望。 1 示例代码 示例代码如下 func TestStringSliceEqualIfBothNil(t *testing.T) {Convey(Given two string slice which are both nil, t, func() {var a []string nilvar b []string nilConvey(When the comparision is done, func() {result : StringSliceEqual(a, b)Convey(Then the result should be true, func() {So(result, ShouldBeTrue)})})}) }func TestStringSliceNotEqualIfNotBothNil(t *testing.T) {Convey(Given two string slice which are both nil, t, func() {a : []string(nil)b : []string{}Convey(When the comparision is done, func() {result : StringSliceEqual(a, b)Convey(Then the result should be false, func() {So(result, ShouldBeFalse)})})}) }func TestStringSliceNotEqualIfBothNotNil(t *testing.T) {Convey(Given two string slice which are both not nil, t, func() {a : []string{hello, world}b : []string{hello, goconvey}Convey(When the comparision is done, func() {result : StringSliceEqual(a, b)Convey(Then the result should be false, func() {So(result, ShouldBeFalse)})})}) } 在实际运用中可以结合第一条方法构成四层嵌套来描述一个测试用例 func TestStringSliceEqual(t *testing.T) {Convey(TestStringSliceEqualIfBothNotNil, t, func() {Convey(Given two string slice which are both not nil, func() {a : []string{hello, goconvey}b : []string{hello, goconvey}Convey(When the comparision is done, func() {result : StringSliceEqual(a, b)Convey(Then the result should be true, func() {So(result, ShouldBeTrue)})})})})Convey(TestStringSliceEqualIfBothNil, t, func() {Convey(Given two string slice which are both nil, func() {var a []string nilvar b []string nilConvey(When the comparision is done, func() {result : StringSliceEqual(a, b)Convey(Then the result should be true, func() {So(result, ShouldBeTrue)})})})})Convey(TestStringSliceNotEqualIfNotBothNil, t, func() {Convey(Given two string slice which are both nil, func() {a : []string(nil)b : []string{}Convey(When the comparision is done, func() {result : StringSliceEqual(a, b)Convey(Then the result should be false, func() {So(result, ShouldBeFalse)})})})})Convey(TestStringSliceNotEqualIfBothNotNil, t, func() {Convey(Given two string slice which are both not nil, func() {a : []string{hello, world}b : []string{hello, goconvey}Convey(When the comparision is done, func() {result : StringSliceEqual(a, b)Convey(Then the result should be false, func() {So(result, ShouldBeFalse)})})})})} 2 大坑 注意Given层中最好只有一个Then因为多个Then会导致每执行完一个Then就会再次执行一遍被测试的函数方法导致多次执行的结果可能并不相同从而导致意料之外的错误比如上面示例中的“result : StringSliceEqual(a, b)”。所以如果选择使用GWT的结构那么就要保证W中只有一个T最好也要保证G中只有一个W。 三、自定义断言函数 断言函数So中第二个参数Assertion类型定义 type Assertion func(actual interface{}, expected ...interface{}) string 返回空字符串表示断言成功否则就是断言失败了。 1 自定义断言函数 所以我们自定义断言函数时也要注意这点下面是一个参考示例 func ShouldSummerBeComming(actual interface{}, expected ...interface{}) string {if actual summer expected[0] comming {return } else {return summer is not comming!} } 上述代码中第一个条件表示断言成功其它所有情况都是断言失败。 2 在So中使用自定义的断言函数 func TestSummer(t *testing.T) {Convey(TestSummer, t, func() {So(summer, ShouldSummerBeComming, comming)So(winter, ShouldSummerBeComming, comming)}) } 测试结果 RUN TestSummerTestSummer ✔✘Failures:* /Users/zhangxiaolong/Desktop/D/go-workspace/src/infra/alg/slice_test.go Line 52:summer is not comming!2 total assertions--- FAIL: TestSummer (0.00s) FAIL exit status 1 FAIL infra/alg 0.006s
http://www.yutouwan.com/news/48577/

相关文章:

  • 洛阳霞光做网站重庆网页制作工作室
  • 深圳生产型企业网站建设专业网站设计制合肥作
  • 关键词网站建设优化建设局跟住建局一样吗
  • zencart 官方网站贵阳国家经济技术开发区门户网站
  • 深圳优秀网站建设定制网站ico如何添加
  • 小白建站软件凡科网账号怎么注销
  • 团购网站建设工程监理网站
  • 建立网站请示企业制作网站一般多少钱
  • 广州网站开发服务外协机械加工订单
  • thinkphp网站建设课程上海建智建设工程咨询
  • 怎样做网站软件网站开发面试都会问什么问题
  • 网站由哪些部分组成部分组成部分庆阳有人做农资网站吗
  • 高端网站设计理念深圳市中心房价
  • 养老网站备案必须做前置审批吗博物馆网站建设经费请示
  • 老河口建设局网站网站建设教程网页
  • 坪山网站建设自动外链工具
  • 网站 无限下拉wordpress 更新 固定链接
  • 济南做网站的好公司有哪些兵团公共资源交易中心
  • 免费可商用的素材网站wordpress黑色名片主题
  • 网站建设开发费入什么科目做外贸网站用什么空间
  • 郓城县建设局网站店铺网络推广有哪些渠道
  • 网站建设襄阳门户网站模板 图片
  • 深圳手机网站建设报价启东做网站的网络公司有哪些
  • 密云网站开发湖南网站建设开发公司
  • 设计方面的网站北京知名的网站建设公司
  • 网站版面特点专业建设研讨会
  • 济南做网站比较好的河南手机网站建设公司哪家好
  • 网站开发报价单 excel比一网站建设
  • 使用网站模板侵权吗高端个人网站
  • 宁波网站关键词排名推广温州公司建设网站制作