如何将我的函数导入到我的测试文件夹中?我在cmd目录中运行,它创建了一个go.mod文件,但是当我尝试在测试中导入它时,我无法访问函数。我在根项目目录中运行,错误是:go mod initmodule "cmd"go test ./testtest/services_test.go:4:2: "cmd" is not an importable package;
myproject
├── cmd
├── main.go (package main)
├── helper.go (package main)
└── services.go (package main)
├── test
├── helper_test.go (package_main)
└── services_test.go (package main)
├── go.mod (module cmd)
└── go.sum
在 cmd/services.go 中
package main
func doStuff() {
// TODO
}
在测试中/services_test.go
package main
import {
"cmd"
"testing"
}
func TestdoStuff (*testing.T) {
cmd.doStuff()
}
慕运维8079593
天涯尽头无女友
慕桂英4014372
收到一只叮咚
随时随地看视频慕课网APP
相关分类