package config_test import ( "testing" "gitlab.com/go-course-project/go17/book/config" ) // LoadConfigFromYaml // go test 它自动帮你写来一个main函数,然后把测试逻辑装进去, 然后编译允许 func TestLoadConfigFromYaml(t *testing.T) { if err := config.LoadConfigFromYaml("application.yaml"); err != nil { // 报错测试失败,并且结束 t.Fatal(err) } // 加载成功 t.Log(config.Get()) }