在复杂的文件夹结构中进行测试

时间:2017-09-17 11:33:45

标签: bash unit-testing testing go

我正在golang中构建一个设计模式的存储库。要运行所有测试,我使用此bash脚本。它有效。

#!/bin/bash
go test creational/abstract_factory/*.go
go test creational/builder/*.go
go test creational/factory/*.go
go test creational/pool/*.go
go test creational/prototype/*.go
go test creational/singleton/*.go

工作正常:

prompt> ./runtests.sh
ok      command-line-arguments  0.006s
ok      command-line-arguments  0.006s
ok      command-line-arguments  0.006s
ok      command-line-arguments  0.006s
ok      command-line-arguments  0.005s
ok      command-line-arguments  0.006s

但是,...如果我尝试向go test发送更多目录,我收到此消息“命名文件必须全部在一个目录中;有创建/池/和创建/工厂/”。这就是我创建bash脚本的原因。

是否可以在一个命令中测试所有文件夹?

1 个答案:

答案 0 :(得分:4)

使用...有什么问题?将目录更改为creational,然后

go test ./...

这将递归到所有子文件夹并执行所有找到的包的测试。有关详细信息,请参阅Difference in output when calling go test with package;和How do you run `go test` when test files are within a module?

注意:从1.9开始,如果使用vendor./...子文件夹中的包不匹配。资料来源:Go 1.9 Release Notes - Vendor matching with ./...。在Go 1.9之前,go test ./...也进入vendor子文件夹并运行了已售出软件包的测试。