Go测试没有运行特定的测试,尽管包含了标记

  • 本文关键字:测试 包含 运行 Go go testing
  • 更新时间 :
  • 英文 :


文件夹结构:

./test
├── abc
│   └── abc_test.go
└── run_test.go

run_test.go

package test
import (
. "gopkg.in/check.v1"
"testing"
)
func Test(t *testing.T) {
TestingT(t)
}

abc_test.go

package abc
import (
"fmt"
. "gopkg.in/check.v1"
)
type TestSuite struct{}
var _ = Suite(&TestSuite{})
func Test(t *testing.T) {
TestingT(t)
}
func (s *TestSuite) SetUpSuite(c *C) {
fmt.Println("start")
}
func (s *TestSuite) TestOne(c *C) {
fmt.Println("start one")
}
func (s *TestSuite) TestTwo(c *C) {
fmt.Println("start two")
}

运行所有测试工作:

go-playground > go test -v ./...                         
?       go-playground   [no test files]
=== RUN   Test
OK: 0 passed
--- PASS: Test (0.00s)
PASS
ok      go-playground/test      (cached)
=== RUN   Test
start
start one
start two
OK: 2 passed
--- PASS: Test (0.00s)
PASS
ok      go-playground/test/abc  0.010s
?       go-playground/tree      [no test files]

尝试只运行一个测试TestOne全部失败

go-playground > go test -v -check=TestOne ./...                                                                                         INT 17:36:03
?       go-playground   [no test files]
go-playground > go test -v -check=abc ./...                                   
?       go-playground   [no test files]
go-playground > go test -v -gocheck.f=TestOne ./...                               
?       go-playground   [no test files]
go-playground > go test -v -gocheck.f TestOne ./...                                
?       go-playground   [no test files]
go-playground > go test -v -gocheck.f TestSuite ./...                               
?       go-playground   [no test files]
go-playground > go test -v -gocheck.f TestSuite ./...                               
?           go-playground   [no test files]
go-playground > go test -v -run TestOne ./test/...                                           
testing: warning: no tests to run
PASS
ok      go-playground/test      (cached) [no tests to run]
testing: warning: no tests to run
PASS
ok      go-playground/test/abc  0.004s [no tests to run]
go-playground > go test -v -run TestOne ./...                                                    
?       go-playground   [no test files]
testing: warning: no tests to run
PASS
ok      go-playground/test      (cached) [no tests to run]
testing: warning: no tests to run
PASS
ok      go-playground/test/abc  (cached) [no tests to run]
?       go-playground/tree      [no test files] 

似乎什么都不起作用。介意指出我错过了什么吗?

这主要是关于"gopkg.in/check.v1"的问题。作为替代方案,您可以使用cd abcgo test -v -check.f=TestOne。这是可行的。你不应该期望go test -run TestOne工作。这不是从go命令的角度进行的测试。从它的角度来看,唯一的测试是func Test(t *testing.T) { TestingT(t) }

关于是否允许组合包路径和包模式匹配使用"gopkg.in/check.v1"如:

go test -v -gocheck。f = TestOne。/…

我不确定。我建议联系这个包的作者http://labix.org/gocheck。

最新更新