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

网站建设的说辞seo销售话术开场白

网站建设的说辞,seo销售话术开场白,django成品网站源码,石家庄免费网站制作快速开始 GoConvey是一个完全兼容官方Go Test的测试框架,一般来说这种第三方库都比官方的功能要强大、更加易于使用、开发效率更高,闲话少说,先看一个example: package utils import (. "github.com/smartystreets/goconvey…

快速开始

在这里插入图片描述

GoConvey是一个完全兼容官方Go Test的测试框架,一般来说这种第三方库都比官方的功能要强大、更加易于使用、开发效率更高,闲话少说,先看一个example:

package utils
import (. "github.com/smartystreets/goconvey/convey""testing"
)func TestSpec(t *testing.T) {Convey("Given some integer with a starting value", t, func() {x := 1Convey("When the integer is incremented", func() {x++Convey("The value should be greater by one", func() {So(x, ShouldEqual, 2)})})})
}

看着复杂, 一层层的嵌套,如果你使用IDE的话你可以点到源码里面看一下其方法注释,其实已经说的非常清楚了,这里摘取部分看一下:

// Convey is the method intended for use when declaring the scopes of
// a specification. Each scope has a description and a func() which may contain
// other calls to Convey(), Reset() or Should-style assertions. Convey calls can
// be nested as far as you see fit.
//
// IMPORTANT NOTE: The top-level Convey() within a Test method
// must conform to the following signature:
//
//     Convey(description string, t *testing.T, action func())
//
// All other calls should look like this (no need to pass in *testing.T):
//
//     Convey(description string, action func())

这个用法相对简单了,Convey定义了一个局部的作用域,在这个作用域里面我们可以定义变量,调用方法,然后重复继续这个操作,low-level的Convey会继承top-level的变量。

了解之后,我们来扩展一下这个例子:

func TestSpec(t *testing.T) {Convey("Given some integer with a starting value", t, func() {x := 1y := 10Convey("When the integer is incremented", func() {x++Convey("The value should be greater by one", func() {So(x, ShouldEqual, 2)})})Convey("When x < y", func() {if x < y {x = x + ySo(x, ShouldBeGreaterThan, y)}})})
}

非常简单,当然这里我们并没有测试任何函数或方法,下面咱们写一个函数真正测试一下,假设有下面的方法:

func Div(a, b int) (int, error) {if b == 0 {return 0, errors.New("can not div zero")}return a / b, nil
}

使用GoConvey的话,测试代码可以这么写:

func TestDiv(t *testing.T) {const X = 10Convey("Normal Result", t, func() {res, err := Div(X, 2)So(res, ShouldEqual, 5)So(err, ShouldBeNil)Convey("Extend Scope", func() {res, err := Div(res, 2)So(res, ShouldEqual, 2)So(err, ShouldBeNil)})})Convey("Error Result", t, func() {res, err := Div(X, 0)So(res, ShouldEqual, 0)So(err, ShouldNotBeNil)})
}

有人可能会觉得这和官方的没多大区别,相当于多加了一个注释,可以对每一个测试用例标识,但是不仅仅如此,这个库还提供了大量增强的Assertions,可以非常方便的对字符串、slice、map结果进行断言测试,具体的话可以查看一下文档或者点进去看看源码注释,这些源码注释基本上已经写的非常清楚了。

Web UI

此外,框架还提供了一个Web端的UI界面,可以非常方便的查看测试覆盖和运行情况,还可以自动运行测试,执行goconvey命令就可以启动服务,快试一试吧!(虽然说像Goland这样的IDE也提供了GUI工具查看测试覆盖率,但是这个更加方便)

另外,这个框架还提供了自定义Assertions的功能,使用起来也很方便,有一个通用的模板:

func should<do-something>(actual interface{}, expected ...interface{}) string {if <some-important-condition-is-met(actual, expected)> {return ""   // empty string means the assertion passed}return "<some descriptive message detailing why the assertion failed...>"
}

举个例子,这里定义一个试试:

func shouldNotGreatThan100(actual interface{}, expected ...interface{}) string {if actual.(int) > 100 {return "too big than 100"} else {return ""}
}

定义通用的逻辑

有时候测试会需要做一些准备工作,而且是重复的,比如说一些初始化操作,这时候就可以定义一个函数完成这件事,不必每次测试重复做,官方文档里面举了一个数据库测试的例子,每次测试前开启事务,测试结束后回滚事务,这里贴一下官方的example,大家看一下,很容易理解:

package main
import ("database/sql""testing"_ "github.com/lib/pq". "github.com/smartystreets/goconvey/convey"
)
func WithTransaction(db *sql.DB, f func(tx *sql.Tx)) func() {return func() {tx, err := db.Begin()So(err, ShouldBeNil)Reset(func() {/* Verify that the transaction is alive by executing a command */_, err := tx.Exec("SELECT 1")So(err, ShouldBeNil)tx.Rollback()})/* Here we invoke the actual test-closure and provide the transaction */f(tx)}
}
func TestUsers(t *testing.T) {db, err := sql.Open("postgres", "postgres://localhost?sslmode=disable")if err != nil {panic(err)}Convey("Given a user in the database", t, WithTransaction(db, func(tx *sql.Tx) {_, err := tx.Exec(`INSERT INTO "Users" ("id", "name") VALUES (1, 'Test User')`)So(err, ShouldBeNil)Convey("Attempting to retrieve the user should return the user", func() {var name stringdata := tx.QueryRow(`SELECT "name" FROM "Users" WHERE "id" = 1`)err = data.Scan(&name)So(err, ShouldBeNil)So(name, ShouldEqual, "Test User")})}))
}
/* Required table to run the test:
CREATE TABLE "public"."Users" ( "id" INTEGER NOT NULL UNIQUE, "name" CHARACTER VARYING( 2044 ) NOT NULL
);
*/
http://www.15wanjia.com/news/55181.html

相关文章:

  • 常用设计网站有哪些软件揭阳百度seo公司
  • 静态网站建设的流程泉州seo代理商
  • 做鞋子有什么好网站郑州seo排名优化
  • 网站建设工作汇报seo网站诊断报告
  • 国贸行业 网站建设柳州网站建设哪里有
  • html做的小网站近期新闻大事
  • 网站制作要多少钱自媒体平台排名前十
  • 饰品网站模版精准广告投放
  • 网站公网安备链接怎么做seo人工智能
  • 关于网站建设的毕业论文案例管理培训
  • 网站访客qq号码获取舆情管理
  • 网站建设公司中心今天特大新闻最新消息
  • 杭州知名建设网站设计独立站平台选哪个好
  • 游戏网站制作板式互联网关键词优化
  • 厦门方易网站制作有限公司公司网站的推广
  • 企业网站策划流程百度关键词挖掘查询工具
  • 天津网站建设解决方案短视频平台推广方案
  • 重庆建设工程造价信息网站电脑培训班一般需要多少钱
  • 欧米茄女士手表网站新网域名注册查询
  • 一般网站建设公司好51趣优化网络seo工程师教程
  • 网站开发职业定位郑州网站制作公司哪家好
  • 网站规划建设与管理维护教学大纲seo网站推广平台
  • 网站图片分辨率百度搜索广告怎么投放
  • 做普通网站多少钱谷歌应用商店app下载
  • 在哪里学做网站深圳网络推广公司有哪些
  • 如何虚拟一个公司网站做网站排名服务热线
  • 如何建立公司网站建设环球资源网站网址
  • 制作图片怎么做seo网站优化推广怎么样
  • 荣成信用建设网站快速建网站
  • 怎么做网站用于推广seo搜索引擎优化主要做什么