ginkgo在windows下的安装使用

ginkgo在windows下的安装使用

ginkgo是GOLANG的一个测试框架

https://github.com/onsi/ginkgo

安装

建一个自己的文件夹,如D:\workspace\go-test-go
在计算机->环境变量中设置GOPATH
打开git bash
执行

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

在git bash中cd到该目录

然后运行下ginkgo help,看下参数列表

Usage of ginkgo:
  -a    Force rebuilding of packages that are already up-to-date.
  -afterSuiteHook string
        Run a command when a suite test run completes
  -asmflags string
        Arguments to pass on each go tool asm invocation.
  -blockprofilerate int
        Control the detail provided in goroutine blocking profiles by calling runtime.SetBlockProfileRate with the given value. (default 1)
  -buildmode string
        Build mode to use. See ‘go help buildmode‘ for more.
  -compiler string
        Name of compiler to use, as in runtime.Compiler (gccgo or gc).
  -compilers int
        The number of concurrent compilations to run (0 will autodetect)
  -cover
        Run tests with coverage analysis, will generate coverage profiles with the package name in the current directory.
  -covermode string
        Set the mode for coverage analysis.
  -coverpkg string
        Run tests with coverage on the given external modules.
  -coverprofile string
        Write a coverage profile to the specified file after all tests have passed.
  -cpuprofile string
        Write a CPU profile to the specified file before exiting.
  -dryRun
        If set, ginkgo will walk the test hierarchy without actually running anything.  Best paired with -v.
  -failFast
        If set, ginkgo will stop running a test suite after a failure occurs.
  -failOnPending
        If set, ginkgo will mark the test suite as failed if any specs are pending.
  -flakeAttempts int
        Make up to this many attempts to run each spec. Please note that if any of the attempts succeed, the suite will not be failed. But any failures will still be recorded. (default 1)
  -focus string
        If set, ginkgo will only run specs that match this regular expression.
  -gccgoflags string
        Arguments to pass on each gccgo compiler/linker invocation.
  -gcflags string
        Arguments to pass on each go tool compile invocation.
  -installsuffix string
        A suffix to use in the name of the package installation directory.
  -keepGoing
        When true, failures from earlier test suites do not prevent later test suites from running
  -ldflags string
        Arguments to pass on each go tool link invocation.
  -linkshared
        Link against shared libraries previously created with -buildmode=shared.
  -memprofile string
        Write a memory profile to the specified file after all tests have passed.
  -memprofilerate int
        Enable more precise (and expensive) memory profiles by setting runtime.MemProfileRate.
  -msan
        Enable interoperation with memory sanitizer.
  -n go test
        Have go test print the commands but do not run them.
  -noColor
        If set, suppress color output in default reporter.
  -nodes int
        The number of parallel test nodes to run (default 1)
  -noisyPendings
        If set, default reporter will shout about pending tests. (default true)
  -outputdir string
        Place output files from profiling in the specified directory.
  -p    Run in parallel with auto-detected number of nodes
  -pkgdir string
        install and load all packages from the given dir instead of the usual locations.
  -progress
        If set, ginkgo will emit progress information as each spec runs to the GinkgoWriter.
  -r    Find and run test suites under the current directory recursively.
  -race
        Run tests with race detection enabled.
  -randomizeAllSpecs
        If set, ginkgo will randomize all specs together.  By default, ginkgo only randomizes the top level Describe/Context groups.
  -randomizeSuites
        When true, Ginkgo will randomize the order in which test suites run
  -regexScansFilePath
        If set, ginkgo regex matching also will look at the file path (code location).
  -seed int
        The seed used to randomize the spec suite. (default 1471744764)
  -skip string
        If set, ginkgo will only run specs that do not match this regular expression.
  -skipMeasurements
        If set, ginkgo will skip any measurement specs.
  -skipPackage string
        A comma-separated list of package names to be skipped.  If any part of the package‘s path matches, that package is ignored.
  -slowSpecThreshold float
        (in seconds) Specs that take longer to run than this threshold are flagged as slow by the default reporter. (default 5)
  -stream
        stream parallel test output in real time: less coherent, but useful for debugging (default true)
  -succinct
        If set, default reporter prints out a very succinct report
  -tags string
        A list of build tags to consider satisfied during the build.
  -toolexec string
        a program to use to invoke toolchain programs like vet and asm.
  -trace
        If set, default reporter prints out the full stack trace when a failure occurs
  -untilItFails
        When true, Ginkgo will keep rerunning tests until a failure occurs
  -v    If set, default reporter print out all specs as they begin.
  -work
        Print the name of the temporary work directory and do not delete it when exiting.
  -x go test
        Have go test print the commands.
 

生成一个测试套



$ ginkgo bootstrap
Generating ginkgo test suite bootstrap for go_test_go in:
        go_test_go_suite_test.go
$ ginkgo generate



查看下生成的文件



$ ls -lrt
total 2
-rw-r--r-- 1 opama None 199 Aug 21 02:06 go_test_go_suite_test.go
-rw-r--r-- 1 opama None 162 Aug 21 02:07 go_test_go_test.go

 

可以在一个已有工程为其添加test文件



D:\workspace\hellogo\src\aaa>ginkgo generate
Generating ginkgo test for Aaa in:
  aaa_test.go

D:\workspace\hellogo\src\aaa>go test
testing: warning: no tests to run
PASS
ok      _/D_/workspace/hellogo/src/aaa  0.309s



用法摘要

ginko的测试代码由一些代码块组成:Describe 代码块描述了被测代码的行为,Context代码块则表示在不同环境下运用这些行为

  • 通常情况下,container块(Describe、Context块)内应该是个It块、BeforeEach、AfterEach或变量声明,而不应该放置断言。在container块中初始化了变量,如果其中一个It改变了它的值,后续的It取到的就是改变了的值,此时初始化变量总是应该在BeforeEach块中

    var _ = Describe("Node", func() {
    
        //  Context("Context test",func() {
        ret := node.GetNode("123")
        result := comm.GetHttp("456")
        //fmt.Print(ret);
        BeforeEach(func() {
            ret = 666
            fmt.Print(ret);
        })
        It("just test suc", func() {
            ret=200
            fmt.Print(ret);
            Expect(ret).Should(Equal(200))
            Expect(result).Should(Equal("456"))
        })
    
        It("just test fail", func() {
            fmt.Print(ret);
            Expect(ret).Should(Equal("123"))
            Expect(result).Should(Equal("4566"))
        })
        //  })
    })
    $ ginkgo
    
    Running Suite: K8sdemo Suite
    ============================
    
    Random Seed: 1472957391
    Will run 2 of 2 specs
    
    666200+666666
     
  • JustBeforeEach在所有BeforeEach块运行完之后并在It块运行之前运行
    var _ = Describe("Node", func() {
    
        //  Context("Context test",func() {
        ret := node.GetNode("123")
        result := comm.GetHttp("456")
        //fmt.Print(ret);
        BeforeEach(func() {
            ret = 666
            fmt.Print(ret);
        })
        JustBeforeEach(func(){
            ret=777
        })
        It("just test suc", func() {
            ret=200
            fmt.Print(ret);
            Expect(ret).Should(Equal(200))
            Expect(result).Should(Equal("456"))
        })
    
        It("just test fail", func() {
            fmt.Print(ret);
            Expect(ret).Should(Equal("123"))
            Expect(result).Should(Equal("4566"))
        })
        //  })
    })
    $ ginkgo
    
    Running Suite: K8sdemo Suite
    ============================
    
    Random Seed: 1472957580
    Will run 2 of 2 specs
    
    666200+666777
  • By用于梳理和标记复杂的流程和步骤,成功了不会显示,失败则将步骤打印出来,通过在Describe、Context、It等加上P或X来标记其为pending
    var _ = Describe("Node", func() {
    
    //  Context("Context test",func() {
            ret :=  node.GetNode("123");
            result := comm.GetHttp("456");
            It("just test suc", func() {
                Expect(ret).Should(Equal(200));
                Expect(result).Should(Equal("456"));
            })
    
            PIt("just test fail", func() {
                Expect(ret).Should(Equal("123"));
                Expect(result).Should(Equal("4566"));
            })
    //  })
    })
    $ ginkgo
    
    Running Suite: K8sdemo Suite
    ============================
    
    Random Seed: 1472956009
    Will run 1 of 2 specs
    
    +
    ------------------------------
    
    P [PENDING]
    Node
    D:/workspace/k8sdemo/src/node_test.go:27
      just test fail
    
      D:/workspace/k8sdemo/src/node_test.go:25
    ------------------------------
    
    Ran 1 of 2 Specs in 0.000 seconds
    SUCCESS! -- 1 Passed | 0 Failed | 1 Pending | 0 Skipped PASS
    
    
    
  • Focused Specs,只运行F开头的用例,也可以使用–focus=REGEXP, 注意该特若在ci中使用会造成exitcode非0
     
    Running Suite: K8sdemo Suite
    ============================
    
    Random Seed: 1472956139
    Will run 1 of 2 specs
    
    S
    ------------------------------
    
    + Failure [0.001 seconds]
    Node
    D:/workspace/k8sdemo/src/node_test.go:27
      just test fail [It]
      D:/workspace/k8sdemo/src/node_test.go:25
    
      Expected
          <int>: 200
      to equal
          <string>: 123
    
      D:/workspace/k8sdemo/src/node_test.go:23
    ------------------------------
    
    Summarizing 1 Failure:
    
    [Fail] Node [It] just test fail
    D:/workspace/k8sdemo/src/node_test.go:23
    
    Ran 1 of 2 Specs in 0.001 seconds
    FAIL! -- 0 Passed | 1 Failed | 0 Pending | 1 Skipped --- FAIL: TestK8sdemo (0.00s)
    FAIL
    
    Ginkgo ran 1 suite in 2.8093489s
    Test Suite Failed
    
    
     
  • 同步方式的使用:SynchronizedBeforeSuite()传入两个func,第一个必须返回[]byte,第二个必须接受这个[]byte,如一个func是在一个节点起一个server返回endpoint,第二个函数是所有节点client接受endpoint并进行连接,并发时clinet需要等待sever启动再进行连接

    同理SynchronizedAfterSuite()传入两个func,第一个func需要全部节点都执行完成,再执行由第一个节点执行第二个func。如在上述的基础上第一个func关闭所有的client,第二个func停止server

    ginko对并发异步也能很好的支持测试,在非container块(its,BeforeEach)等增加了一个可选的参数func(done Done),ginkgo检查到done Done参数,遍用goroutine的方式运行body函数,需要通过关闭done channel或发送消息到channel来告诉ginkgo运行完成。如果超时了运行还未结束,ginkgo将把它标记为fail。运行下一个。

  • ginkgo常用命令:
    并行
    gingkgo 快速启动测试
    -p 并行
    --nodes=Node_total 指定并发节点数
    
    控制
    -r 遍历目录
    -skipPackage skip目录
    
    输出
    --noColor 无颜色
    --succinct 精简打印一行
    --v 详细打印用例的文本和位置
    --noisyPending 对pending的specs也给出信息
    --trace 失败打印堆栈信息
    --progress 将进入和运行每个部分的日志都打印出来 
    
    随机
    --seed=SEED
    
    focus和skip
    --skipMeasurements
    --focus=REGEXP
    --skip=REGXP
    
    coverage
    -race
    -cover
    
    失败动作
    --failOnPending 有pending的specs就认为是fail
    --failFast 失败就停止suite的运行
    
    其他
    -dryRun 只是遍历,非真实运行
    -keepGoing 多个suite有一个失败了仍能继续
    -untilItFails 一直运行知道失败
    --slowSpecThreshold=TIME_IN_SECONDS 标记运行缓慢的spec
    并行
    gingkgo 快速启动测试
    -p 并行
    --nodes=Node_total 指定并发节点数
    
    控制
    -r 遍历目录
    -skipPackage skip目录
    
    输出
    --noColor 无颜色
    --succinct 精简打印一行
    --v 详细打印用例的文本和位置
    --noisyPending 对pending的specs也给出信息
    --trace 失败打印堆栈信息
    --progress 将进入和运行每个部分的日志都打印出来 
    
    随机
    --seed=SEED
    
    focus和skip
    --skipMeasurements
    --focus=REGEXP
    --skip=REGXP
    
    coverage
    -race
    -cover
    
    失败动作
    --failOnPending 有pending的specs就认为是fail
    --failFast 失败就停止suite的运行
    
    其他
    -dryRun 只是遍历,非真实运行
    -keepGoing 多个suite有一个失败了仍能继续
    -untilItFails 一直运行知道失败
    --slowSpecThreshold=TIME_IN_SECONDS 标记运行缓慢的spec
    
    预编译
    ginkgo build xxxx
    生成xxxx.test
    ginkgo -p xxxx.test
    
    将xuint的转为ginkogo
    ginkgo convert xxxx
    
    benchmark tests
    
    
  • TABLE DRIVEN TESTS
    使用Entry、DescrieTable将数据抽离出来传给函数去执行,这个有点像TestNg的DataProvider
时间: 2024-10-13 22:36:04

ginkgo在windows下的安装使用的相关文章

Windows下redis 安装与PHP使用

http://alfred-long.iteye.com/blog/1684545 一. 安装redis及启用服务 1 下载redis客户端 http://code.google.com/p/servicestack/wiki/RedisWindowsDownload#Download_32bit_Cygwin_builds_for_Windows 2 解压到你所需要的目录中 3 创建redis.conf文件 Redis.conf代码   # Redis configuration file e

Oracle instant client在windows下的安装和使用【转】

[转] Oracle instant client在windows下的安装和使用 转载自 placidcreate 最终编辑 placidcreate [安装]从oracle官方网站下载instant client文件,(http://www.oracle.com/technetwork/topics/winx64soft-089540.html) 一般来说,有basic.sqlplus.odbc.jdbc,就足够用的了: instantclient-basic-win32-11.2.0.1.0

[Redis]windows下redis安装

官方的下载地址是: http://redis.io/download 在win64一栏中可以看到redis原本是没有windows版本的,windows版本是Microsoft Open Tech团队开的 给出了一个github的链接地址: https://github.com/MSOpenTech/redis 下载: 在https://github.com/MSOpenTech/redis  页面的右下角有  Download Zip的字样,点击之后就可以下载源码的zip包了. 然后就是解压:

memcache的windows下的安装和简单使用

原文:memcache的windows下的安装和简单使用 memcache是为了解决网站访问量大,数据库压力倍增的解决方案之一,由于其简单实用,很多站点现在都在使用memcache,但是memcache缺点之一却是缺少安全性验证,所以一般而言我们都会把一些访问量大,但是不需要验证的数据放在这里,需要用的时候来这里取,就给数据库减少了很多的负担.一般而言设定个更新时间就好了,1个小时左右更新一次. windows下安装和测试memcache最为方便,Linux只是需要相应的编译包就行了,需要包括m

Windows下Django安装

Windows下django安装 1.首先保证你的电脑上安装了python,如果没有请自行百度安装(5555555555,居然链接). 2.到Django官网(https://www.djangoproject.com/download/)下载安装包,是压缩文件包,Django-1.9.7.tar.gz. 3.解压Django-1.9.7.tar.gz包,到python同一级目录. 4.Cmd进入到python的目录的上一级目,然后进入到Django-1.9.7目录. 5.执行python se

Windows下pry安装和配置

pry是一个增强型的交互式命令行工具,比irb强大. 有自动完成功能,自动缩进,有颜色.有更强大的调试功能. pry 安装很简单. 在终端输入: gem install pry 然后就会自动到网上下载安装了. 设置 在windows上pry默认没有打开自动缩进和颜色功能. 需要配置一下. pry配置 放在个人目录下的pryrc文件里(文件路径: %USERPROFILE%\ .pryrc). 配置文件默认不存在,需要新建一个,在里面输入 #这是pry的配置文件,pry运行前会读取此文件的配置,

windows下VMware安装Ubuntu的文件共享(VM-tools)

因为工作的需要,最近用到了Vm-ware虚拟机,我用的是win7+vmware+ubuntu的配置,相信很多人都用过类似的环境,下面我就说说文件共享的问题,虽然网上有很多教程,但是感觉都不全面,至少我也是找了好几个拼凑起来才搞定这个问题. 首先,需要安装VM-tools,这个比较简单,直接借用别人的方法贴出来: 1.安装工具.让虚拟机运行于窗口状态,不要全屏,按Ctrl+Alt让鼠标释放出来.在VMware的菜单栏上选择"虚拟机/安装虚拟机工具(VM/Install VMware Tools..

Windows下虚拟机安装Mac OS X &mdash;&ndash; VM12安装Mac OS X 10.11

______________________________________________________________________________________________________________________________________________________________________________________________________________________ 注:本文来源:csdn:N的专栏.<Windows下虚拟机安装Mac

Windows下caffe安装详解(仅CPU)

本文大多转载自 http://blog.csdn.net/guoyk1990/article/details/52909864,加入部分自己实战心得. 1.环境:windows 7\VS2013 2.caffe-windows准备 (1)下载官方caffe-windows并解压,将 .\windows\CommonSettings.props.example备份,并改名为CommonSettings.props.如图4所示: 图 4:修改后的CommonSettings.props文件 附带说明