【问题标题】:go test in complex folder structure在复杂的文件夹结构中进行测试
【发布时间】:2017-09-17 11:33:44
【问题描述】:

我正在用 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 发送更多目录,我会收到此消息“命名文件必须全部位于一个目录中;具有creational/pool/ 和creational/factory/”。这就是我创建该 bash 脚本的原因。

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

【问题讨论】:

    标签: bash unit-testing testing go


    【解决方案1】:

    使用... 有什么问题?将目录更改为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 子文件夹并运行了供应商包的测试。

    【讨论】:

      猜你喜欢
      • 2017-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多