4

【笔记】Go语言的单元测试

 1 year ago
source link: https://loli.fj.cn/2023/05/18/Go%E8%AF%AD%E8%A8%80%E7%9A%84%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

【笔记】Go语言的单元测试

Go语言的单元测试学习笔记

  • 单元测试的文件名必须以_test结尾,函数名必须以Test开头,并且函数名中被测试的方法名Xxx首字母必须大写

模块名_test.go

package main

import testing

func TestXxx(t *testing.T) {

var res = 被测试的函数(参数)
if res != 预期值 {
t.Fatalf("错误")
} else {
t.Logf("正确")
}

}

对当前模块进行单元测试

go test -v

哔哩哔哩——尚硅谷


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK