【问题标题】:Run go test for specific package对特定包运行 go test
【发布时间】:2019-05-03 10:36:42
【问题描述】:

我使用以下命令对特定包运行测试

go test fts -run run_test.go

无法加载包:包 fts:在以下任何位置都找不到包“fts”:/usr/local/Cellar/go/1.11.1/libexec/src/integration(来自 $GOROOT)/Users/i055555/ go/src/fts(来自 $GOPATH)

而且包裹看起来像

gitproj/
    |---- fts
      |---- -command
        |---- -run.go
         |---- -run_test.go
    |---- internal
        |---- -fs.go
           |---- -tb.go
           |---- -tb_test.go
    main.go

【问题讨论】:

  • 如果它不在您的 GOPATH 中,请尝试使用相对路径运行它,例如go test ./fts/command

标签: go


【解决方案1】:

因此,您可以通过为特定包提供相对路径来运行 go test

go test ./fts/command

--run 标志采用正则表达式,有助于指示将在包中运行哪些测试。

例如,如果您有一个名为 TestFoo(...) 的测试和另一个名为 TestBar(...) 的测试。 go test --run=TestFoo 只会运行 TestFoo(...)

【讨论】:

  • 我试过了,它不工作,也许是因为我用银杏?它有不同的表现吗?
  • Ginkgo 绑定到测试框架,所以应该没问题
猜你喜欢
  • 2021-10-19
  • 1970-01-01
  • 2019-08-09
  • 1970-01-01
  • 1970-01-01
  • 2020-12-30
  • 1970-01-01
  • 2012-12-24
  • 1970-01-01
相关资源
最近更新 更多