Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add go test #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion languages/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ GOSSAFUNC // 生成SSA.html文件,
go mod init // 初始化当前文件夹,创建go.mod文件
go mod download // 下载依赖的module到本地
go mod tidy // 增加缺少的module,删除无用的module
go mod vendor // 将依赖复制到vendor下
go mod vendor // 将依赖的包复制到vendor文件夹下
文件go.mod // 依赖列表和版本约束
文件go.sum // 记录module文件hash值,用于安全校验

Expand Down Expand Up @@ -116,6 +116,42 @@ const d = 1 // 常量



/*******************************************************************************
* 测试
******************************************************************************/
// 要测试的接口
package testdemo

func Adder(a int, b int) int {
return a + b
}

// 编写test
package testdemo

import "testing"

func TestPass(t *testing.T) {
expected := 3
if observed := Adder(1, 2); observed != expected {
t.Fatalf("Adder(1, 2) = %v, want %v", observed, expected)
}
}

func TestSkip(t *testing.T) {
t.Skip("Skipping test")
}

func TestFail(t *testing.T) {
expected := 3
if observed := Adder(2, 2); observed != expected {
t.Fatalf("Adder(2, 2) = %v, want %v", observed, expected)
}
}

// 运行命令
go test -v mod/{package_name}


/*******************************************************************************
* 数据类型
Expand Down Expand Up @@ -271,3 +307,4 @@ https://github.com/avelino/awesome-go
******************************************************************************/
https://github.com/a8m/go-lang-cheat-sheet
https://github.com/LeCoupa/awesome-cheatsheets
https://github.com/jonasbn/go-test-demo