BDD

What is Behaviour Driven Development and why should I care?

Behaviour Driven Development (BDD) is a testing methodology that has evolved from Test Driven Development (TDD). BDD is a useful way to describe your test cases from the perspective of the user. It uses a Given-When-Then format that is cognitively easy to parse. The output can be debugged and understood by both technology & business stakeholders. If you have used Behat, Cucumber etc in the past, this would be familiar to you.

Given: The user name is ABCD and the password is PWD
When: the user inputs these credentials and Clicks on enter
Then: the user should be logged in

Go ships with a fantastic testing library. More often than not, that testing library suffices the requirements. But, at Exotel, we’ve adopted the BDD methodology simply because it gives more user-readable expressions and some of the constraints imposed by the framework force developers to avoid cryptic error messages. Also, the long-term goal was to let the QA team or the business owners themselves to add test cases as and when they see something failing.

There are a bunch of decent BDD frameworks written for Go: Ginkgo , Goblin & GoConvey . We use Ginkgo heavily within our applications. Now, let’s get to the interesting part and show you how to use Ginkgo in your next application.

Popular Frameworks

ginkgo

prepare

$ go get github.com/onsi/ginkgo/ginkgo
$ go get github.com/onsi/gomega

$ cd book
$ ginkgo init # https://stackoverflow.com/questions/25879473/how-do-i-set-up-a-ginkgo-test-suitee
$ ginkgo bootstrap $ cat book.go
 package book

 import (
_ "fmt"
) type Book struct {
Title string
Author string
Pages uint
} func (b *Book) CategoryByLength() string {
if b.Pages >= {
return "NOVEL"
}
return "SHORT STORY"
}

$ cat src_suite_test.go

 package book_test

 import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" "testing"
) func TestSrc(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Src Suite")
}

$ cat book_test.go

 package book_test

 import (
. "book" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
) var _ = Describe("Book", func() {
var (
longBook Book
shortBook Book
) BeforeEach(func() {
longBook = Book{
Title: "Les Miserables",
Author: "Victor Hugo",
Pages: ,
} shortBook = Book{
Title: "Fox In Socks",
Author: "Dr. Seuss",
Pages: ,
}
}) Describe("Categorizing book length", func() {
PContext("With more than 300 pages", func() {
It("should be a novel", func() {
Expect(longBook.CategoryByLength()).To(Equal("NOVEL"))
})
}) Context("With fewer than 300 pages", func() {
It("should be a short story", func() {
Expect(shortBook.CategoryByLength()).To(Equal("SHORT STORY"))
})
}) Context("Do panics test", func() { It("panics in a goroutine", func(done Done) {
go func() {
defer GinkgoRecover() Ω(func() bool { return true }()).Should(BeTrue()) close(done)
}()
})
})
})
})


Run Test

I try  $ ginkgo to run the test. no any response. so I use:

$ go test -ginkgo.v

Pending/Skip some test case

You do this by adding a P or an X in front of your Describe, Context, It, and Measure:

only test some case:

by adding an F in front of your Describe, Context, and It.

convey

Good to explain BDD with GO

https://semaphoreci.com/community/tutorials/getting-started-with-bdd-in-go-using-ginkgo

https://blog.codeship.com/implementing-a-bdd-workflow-in-go/

golang BDD testcase framework.的更多相关文章

  1. Go语言(golang)开源项目大全

    转http://www.open-open.com/lib/view/open1396063913278.html内容目录Astronomy构建工具缓存云计算命令行选项解析器命令行工具压缩配置文件解析 ...

  2. [转]Go语言(golang)开源项目大全

    内容目录 Astronomy 构建工具 缓存 云计算 命令行选项解析器 命令行工具 压缩 配置文件解析器 控制台用户界面 加密 数据处理 数据结构 数据库和存储 开发工具 分布式/网格计算 文档 编辑 ...

  3. Why I Left the .NET Framework

    The .NET Framework was good. Really good. Until it wasn't. Why did I leave .NET? In short, it constr ...

  4. Golang优秀开源项目汇总, 10大流行Go语言开源项目, golang 开源项目全集(golang/go/wiki/Projects), GitHub上优秀的Go开源项目

    Golang优秀开源项目汇总(持续更新...)我把这个汇总放在github上了, 后面更新也会在github上更新. https://github.com/hackstoic/golang-open- ...

  5. Awesome Go精选的Go框架,库和软件的精选清单.A curated list of awesome Go frameworks, libraries and software

    Awesome Go      financial support to Awesome Go A curated list of awesome Go frameworks, libraries a ...

  6. GO语言的开源库

    Indexes and search engines These sites provide indexes and search engines for Go packages: godoc.org ...

  7. Awesome Go

    A curated list of awesome Go frameworks, libraries and software. Inspired by awesome-python. Contrib ...

  8. Go 语言相关的优秀框架,库及软件列表

    If you see a package or project here that is no longer maintained or is not a good fit, please submi ...

  9. go语言项目汇总

    Horst Rutter edited this page 7 days ago · 529 revisions Indexes and search engines These sites prov ...

随机推荐

  1. NSA Fuzzbunch中EternalRomance工具复现过程

    自Shadow Brokers公布NSA泄露工具后,各路大神陆陆续续发表复现过程,这几天也仔细试了各种套路,一直想弄明白DoublePulsar中的shellcode到底是如何用的,刚好又在模拟环境中 ...

  2. model.addattribute()的作用

    1.往前台传数据,可以传对象,可以传List,通过el表达式 ${}可以获取到, 类似于request.setAttribute("sts",sts)效果一样. 2.@ModelA ...

  3. vue中强制刷新的bug处理

    vue是单页面应用,跳转路由也是局部刷新,这里就拿后台管理系统而言,如果你的后台管理系统是左右布局,你不会遇到这样的问题,但是如果你的后台管理系统是上左右布局,你就会遇到这个问题,一级菜单在最上面,二 ...

  4. 连接mysql && ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)

    上一篇:mysql服务正在启动 mysql服务无法启动 && mysql启动脚本 mysql关闭脚本 此篇目编写一个核心目的: 1.mysql连接 先抛出一个问题 这是因为mysql服 ...

  5. React-Native组件之Text内文字垂直居中方案

    style: { height: 100, textAlign: 'center', textAlignVertical: 'center', } 以上方法在Android上显示水平垂直居中, 但在I ...

  6. Beta冲刺阶段3.0

    1. 提供当天站立式会议照片一张 2. 每个人的工作 (有work item 的ID) 成员 昨天已完成的工作 今天计划完成的工作 工作中遇到的困难 具体贡献 郑晓丽 完成"我的活动&quo ...

  7. CSS选择符-----属性选择符

       Element[att] 选择具有att属性的E元素 <!DOCTYPE html> <html> <head> <meta charset=" ...

  8. Rower Bo (高数 + 物理)

    #include<bits/stdc++.h> #define esp (1e-5) using namespace std; int main(){ int a; double v1, ...

  9. android手机平板如何使用usb有线网卡

    最近有个项目需要在android平板上使用usb有线网卡,所以做了一部分工作,在这里简单总结一下. 我在TB上购买了一个micro-usb接口的android免驱有线网卡,这个网上很多,随便买一个符合 ...

  10. locust 的使用

    Contents Locust这一款开源性能测试工具.然而,当前在网络上针对Locust的教程极少,不管是中文还是英文,基本都是介绍安装方法和简单的测试案例演示,但对于较复杂测试场景的案例演示却基本没 ...