Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 在多个go模块的父目录中运行“go测试”_Unit Testing_Go_Testing - Fatal编程技术网

Unit testing 在多个go模块的父目录中运行“go测试”

Unit testing 在多个go模块的父目录中运行“go测试”,unit-testing,go,testing,Unit Testing,Go,Testing,看看这个目录结构: /root /one go.mod go.sum main.go main_test.go /two go.mod go.sum main.go main_test.go 假设我在父目录root/中,我想运行所有子目录中的所有测试。我该怎么办?我尝试了进行测试。/…,但出现以下错误: go: warning: "./..." mat

看看这个目录结构:

/root
    /one
        go.mod
        go.sum
        main.go
        main_test.go
    /two
        go.mod
        go.sum
        main.go
        main_test.go
假设我在父目录
root/
中,我想运行所有子目录中的所有测试。我该怎么办?我尝试了
进行测试。/…
,但出现以下错误:

go: warning: "./..." matched no packages
no packages to test

是的,这将不适用于
go test
,该测试预期适用于根在当前目录或其父目录中的单个模块。它也不适用于嵌套模块

您需要一个shell技巧,比如使用
find
或在每个模块中执行的等效程序(例如,请参见Cerise Limón的评论)。项目通常会使用
Makefile
test.sh
脚本来运行该脚本


其中一个有一个所有模块的列表(),然后是几个在此列表上运行的脚本。例如,服务器只需此文件,并为每个目录运行
go test
,以及其他内容


您不一定需要一个单独的文件来列出模块(go cloud项目将其用于其他管理任务),但它只是演示了具有多个模块的大型项目处理事情的一种方式。

find-名称go.mod-execdir go test./…\