zoukankan      html  css  js  c++  java
  • 【原创】go语言学习(十九)测试用例

    目录

    • 单元测试
    • 压力测试
    • Go test命令介绍

    单元测试

    1、自动化测试框架

    testing
    A. testing包提供了自动化测试相关的框架
    B. 支持单元测试和压力测试

    import (
        “testing”
    )
    

      

    2、测试规范

    Go中的测试约定
    A. 用来测试的代码必须以_test.go结尾
    B. 单元测试的函数名必须以Test开头, 并且只有一个参数,类型是 *Testing.T
    C. 基准测试或压力测试必须以 Benchmark开头,并且只有参数,
    类型是*Testing.B

    import (
    “testing”
    )
    func TestAdd(t *testing.T) {
    }
    

      

    import (
    “testing”
    )
    func BenchmarkAdd(t *testing.B) {
    }
    

      

    3、单元测试

    A. 对于各个分支进行测试,如果不符合预期则失败
    B. 使用testing.T这个对象进行单元测试控制

    压力测试

    1、基准测试

    A. 主要用来做性能测试。
    B. go test自动会执行所有的基准测试,并且打印执行耗时统计

    package main
    import (
        "fmt"
        “testing"
    )
    func BenchmarkHello(b *testing.B) {
        for i := 0; i < b.N; i++ {
            fmt.Sprintf("hello")
        }
    }
    

      

    Go test命令介绍

    A. go test加报名,执行这个包下面的所有测试用例
    B. Go test加测试源文件,执行这个测试源文件里的所有测试用例
    C. go test -run选项,执行只定的测试用例

  • 相关阅读:
    Git连接Github
    全民来打飞机~~(设计探讨)
    mongo学习
    redis aop持久化
    redis的超时删除策略
    redis 学习,没事的时候看看增长知识面
    MySQL query / clause execution order
    用redis做超时判断 感觉写的很有意思
    python 编码问题(转载)
    git 个人学习
  • 原文地址:https://www.cnblogs.com/wangshuyang/p/11815821.html
Copyright © 2011-2022 走看看