zoukankan      html  css  js  c++  java
  • 单元测试

    Golang Unit Testing - GoLang Docs https://golangdocs.com/golang-unit-testing

    Golang Testing单元测试指南 - sunsky303 - 博客园 https://www.cnblogs.com/sunsky303/p/11818480.html

    Go语言重新开始,Go Modules的前世今生与基本使用 https://mp.weixin.qq.com/s/LIIyUQemHPiQkMwTMFsXKw

    首先创建一个新目录/home/gopher/hello,然后进入到这个目录中,接着创建一个新文件,hello.go:

    package hellofunc Hello() string {    return "Hello, world."}

    然后再写个对应的测试文件hello_test.go:

    package helloimport "testing"func TestHello(t *testing.T) {    want := "Hello, world."    if got := Hello(); got != want {        t.Errorf("Hello() = %q, want %q", got, want)    }}

    现在我们拥有了一个package,但它还不是一个Module,因为还没有创建go.mod文件。如果在/home/gopher/hello目录中执行go test,则可以看到:$go test

    go:go.mod file not found in current directory or any parent directory;see'go help modules'

    可以看到Go命令行提示没有找到go.mod文件,可以参考Go help Modules。这样的话可以使用Go mod init来初始化一下,然后再执行Go test:

    go mod init example.com/hellogo: creating new go.mod: module example.com/hellogo: to add module requirements and sums:go mod tidy$go mod tidygo go testPASSok example.com/hello  0.020s$

    这样的话,Module测试就完成了。然后执行的go mod init命令创建了一个go.mod文件:

    $ cat go.modmodule example.com/hellogo 1.17
  • 相关阅读:
    xdoj 1237 (贪心+逆向思维)
    linux系统 (实验一)实验楼的课程笔记
    fc_net.py cs231n
    cnn.py cs231n
    optim.py cs231n
    layers.py cs231n
    Python数据分析与展示[第一周]
    配置了两天python【python可以的】
    PYTHON网络爬虫与信息提取[scrapy框架应用](单元十、十一)
    PYTHON网络爬虫与信息提取[正则表达式的使用](单元七)
  • 原文地址:https://www.cnblogs.com/rsapaper/p/15571894.html
Copyright © 2011-2022 走看看