补充单元测试

This commit is contained in:
yumaojun03 2024-11-16 17:53:04 +08:00
parent 1c7fd10b53
commit bb8d788610
3 changed files with 16 additions and 0 deletions

View File

@ -77,3 +77,18 @@ type Stringer interface {
## debug 测试 ## debug 测试
才是一个程序员入门的标准,
Debug是一个什么事儿: 让你的代码 一行一行的运行,你人肉观察 程序的每一步 是否符合你的预期(这里的变量是不是对的)
1. 添加程序断点: 程序停止那里,等待运行
![alt text](image-2.png)
+ Continue: 继续到下一个端点
+ Step Over: 下一步
+ Step In: 单步调试
+ Step Out: 跳出当前调试步骤
学了Debug 遇到了问题,写个单元测试,看程序每一步的运行状态是否是正确的。

BIN
book/config/image-2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -7,6 +7,7 @@ import (
) )
// LoadConfigFromYaml // LoadConfigFromYaml
// go test 它自动帮你写来一个main函数然后把测试逻辑装进去, 然后编译允许
func TestLoadConfigFromYaml(t *testing.T) { func TestLoadConfigFromYaml(t *testing.T) {
if err := config.LoadConfigFromYaml("application.yaml"); err != nil { if err := config.LoadConfigFromYaml("application.yaml"); err != nil {
// 报错测试失败,并且结束 // 报错测试失败,并且结束