how go test exactly work

package demo

// what exactly go test do
// 一个进程跑多个函数测试
// 每个测试函数一个协程
// 但是这些协程是串行跑的
import (
"fmt"
// "os"
"runtime"
"testing"
"time"
)

func GetGoID() {
var buf [1024]byte
n := runtime.Stack(buf[:], false)
fmt.Println(string(buf[:n]))
}

func TestAdd(t *testing.T) {
GetGoID()
// c := Add(1, 1)
// if c != 2 {
// t.Fatal("")
// }
// fmt.Printf("[TestAdd] pid: %d\n", os.Getpid())
time.Sleep(time.Second * 3)
fmt.Println("TestAdd end")
}

func TestAfter(t *testing.T) {
GetGoID()
// fmt.Println("before TestAfter")
// time.Sleep(time.Second * 3)
// fmt.Printf("[TestAfter] pid: %d\n", os.Getpid())
fmt.Println("end TestAfter")
}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容