当前位置:网站首页>Vscode creates golang development environment and debug unit test of golang
Vscode creates golang development environment and debug unit test of golang
2022-07-27 07:10:00 【Tie Zhu】
One . Preface
vscode It's easy to use , It's really hard to change to heavy ide Go to . however vscode Of debug It really can't compare with the old brand ide Self contained , Therefore, we can only rely on ourselves to install ..
Two . Text
1.vscode An extension of
(1) Search extension go, install
(2)ctrl_cammand+P , Input go:install, Download plug-ins over the wall
(3) If set go mod The way , that vscode Only one project folder can be opened at a time . Otherwise, it will report a mistake :
could not import xx $GOROOT
could not import xx $GOPATH
(4) Copy ignored $ Sign problem :
Open Settings , Search for wordSeparators, Remove from regular matching $
(5) Check the git submitter , Submit the record
Install the extension :git history and gitLens
(6)vscode Preview the page and open multiple windows
1) Open Settings , Search for Enable PreView, Uncheck
2)settings New settings :"workbench.editor.showTabs":true
(7) vscode debugging go Code : install delve
Reference resources :https://www.jianshu.com/p/d8e09faf498c
(8) understand goroot,gopath as well as go mod
Reference resources :https://blog.csdn.net/zkyapple/article/details/112108283
(9)vscode Shrink all code in the file , Open shrink
Collapse code block shortcut
command + k + 0 # Long press command
Expand code block shortcut
command + k + j # Long press command
(10)vscode close go Automatic formatting code
(1) Open Settings , Search for : format on save
(2) find go part , open setting, Some fields will be automatically configured , All set to false that will do
2.vscode Unit test
(1) Find the method file sibling directory to call , For example, the file to be called is xxx.go
(2) New test file xxx_test.go, keep package Agreement . And the method name needs Test start
(3) Mainly used golang Of testing package . The pseudocode is as follows
package xx
run test | debug test
func Testxx(t *testing.T) {
// Initialize the configured code . from main.go Copy in , Ensure that the project can be loaded into the configuration , Like links mysql etc.
// Construct parameters by yourself , Just call the method
err : = xxxx( Self constructed parameters )
}
(4) At this point, we click on run test that will do .
(5)run test You can't fmt Print ?
"go.testFlags": ["-v"]
After setting , our format It will come out after printing
3 .vscode Of debug
(1) First of all, you should know your own cpu framework , at present mac It is mainly divided into amd and arm Of .
Bloggers are m1 chip , That is to say arm Of , So install arm Version of golang.
(2)golang The version is greater than 1.6 ( Looks like the previous version debug A bit of a problem. )
(3) install dlv
go get -u github.com/go-delve/delve/cmd/dlv
(4) Click debug test , Will ask to create launch.json, Agree .
Mainly choose go. Use vscode Default generated json that will do
{
// Use IntelliSense Learn about properties .
// Hover to see the description of an existing property .
// For more information , Please visit : https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}"
}
]
}
(5) Breaking point , perform debug test
(6) Error message
Report errors :could not launch process: can not run under Rosetta, check that the installed build of
Go is right for your CPU architecture Process exiting with code: 1
programme :
1. download golang Of arm , And the version should be greater than 1.6
2. reinstall dlv ( The reason for the mistake lies in , It uses the previous version dlv, Download again )
go get -u github.com/go-delve/delve/cmd/dlv
Basically, you can use it happily after following these steps vscode Of debug The function of . I can't help but say that I'm really invincible , The variable value of each step can be displayed , Debugging artifact . I can't help thinking of the days when I used to print debugging programs , It's really green .
end
边栏推荐
- DataScience:数据生成之在原始数据上添加小量噪声(可自定义噪声)进而实现构造新数据(dataframe格式数据存储案例)
- Summary of APP launch in vivo application market
- Neural network parameter initialization
- R2live code learning record (3): radar feature extraction
- About the new features of ES6
- R2LIVE代码学习记录(3):对雷达特征提取
- 【12】 Understand the circuit: from telegraph to gate circuit, how can we "send messages from thousands of miles"?
- Express framework
- 含有偶氮苯单体的肽核酸寡聚体(NH2-TNT4,N-PNAs)齐岳生物定制
- DNA科研实验应用|环糊精修饰核酸CD-RNA/DNA|环糊精核酸探针/量子点核酸探针
猜你喜欢

基于SSM医院预约管理系统

【12】 Understand the circuit: from telegraph to gate circuit, how can we "send messages from thousands of miles"?

Watermelon book chapter 3 - linear model learning notes

Visual horizontal topic bug1:filenotfounderror: could not find module 'mvcameracontrol dll‘ (or one of it

Netease Yunxin appeared at the giac global Internet architecture conference to decrypt the practice of the new generation of audio and video architecture in the meta universe scene

泛型 -- 学会它,好处多多

VScode连接远程服务器开发

Cyclegan parsing

Digital image processing -- Chapter 3 gray scale transformation and spatial filtering

DNA科研实验应用|环糊精修饰核酸CD-RNA/DNA|环糊精核酸探针/量子点核酸探针
随机推荐
Introduction to the official functions of easyrecovery14 data recovery software
CASS11.0.0.4 for AutoCAD2010-2023免狗使用方法
Book borrowing management system based on SSM
ESP8266(ESP-12F) 第三方库使用 -- SparkFun_APDS9960 (手势识别)
Summary of APP launch in vivo application market
The vscode run command reported an error: the mark "&" is not a valid statement separator in this version.
ZnS-DNA QDs近红外硫化锌ZnS量子点改性脱氧核糖核酸DNA|DNA修饰ZnS量子点
Consideration on how the covariance of Kalman filter affects the tracking effect of deepsort
C time related operation
Basic statement of MySQL (1) - add, delete, modify and query
Watermelon book learning notes - Chapter 4 decision tree
Livox SLAM(带LIO+闭环检测优化)
VScode连接远程服务器开发
Event capture and bubbling - what is the difference between them?
AI: play games in your spare time - earn it a small goal - [Alibaba security × ICDM 2022] large scale e-commerce map of risk commodity inspection competition
脱氧核糖核酸DNA修饰氧化锌|DNA修饰纳米金颗粒|DNA偶联修饰碳纳米材料
Reasoning speed of model
Speech and language processing (3rd ed. draft) Chapter 2 - regular expression, text normalization, editing distance reading notes
vscode运行命令报错:标记“&&”不是此版本中的有效语句分隔符。
Dsgan degenerate network