正如评论中提到的,您可以运行
go test -cover -coverpkg "api_client" "api_client_tests"
进行覆盖测试。
但是将代码文件从测试文件拆分到其他目录并不是Go的方法。
我想您想进行一次黑盒测试(包私有的东西在外部都无法访问,即使对于测试也是如此)。
为此,可以在另一个程序包中进行测试(不移动文件)。例:
api_client.go
package api_client// will not be accessible outside of the packagevar privateVar = 10func Method() {}api_client_test.go
package api_client_testsimport "testing"func TestClient(t *testing.T) { Method()}


