技术共享

vscode编译环境配置-golang

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

1. 支持跳转

如果单测函数上方不显示run test | debug test,需要安装Code Debugger(因为以前的go Test Explorer不再被维护了)
在这里插入图片描述

2. 单测

  • 指定单个用例测试
go test -v run TestXXX
  • 1
  • dlv 调试
    需要安装匹配的go版本和delve版本(如go1.18版本、delve1.20版本)
go install github.com/go-delve/delve/cmd/[email protected]
  • 1
dlv test
  • 1
  • 生成并查询覆盖率
go test -v -cover ./{dir}/... -coverprofile={cov-out-file-path}
  • 1

go tool cover --html={cov-out-file-path} -o={html-path}