我为我的struct(https://github.com/stretchr/testify#suite-package)设置了一个测试套件。在我通过仅指定模式运行单个测试之前:
go test -v ./services/gateways/... -run mytest
此方法在转换后无效。运气不好或有办法吗?
答案 0 :(得分:8)
您可以通过指定-testify.m
参数来运行单个方法。
运行this suite method命令是:
go test -v github.com/vektra/mockery/mockery -run ^TestGeneratorSuite$ -testify.m TestGenerator
答案 1 :(得分:1)
我认为你使用该软件包是SOL的,但这里采用类似的方法来使用go 1.7的库存测试工具:
package main
import "testing"
func TestSuite1(t *testing.T) {
t.Run("first test", func(t *testing.T) { t.Fail() })
t.Run("second test", func(t *testing.T) { t.Fail() })
}
func TestSuite2(t *testing.T) {
t.Run("third test", func(t *testing.T) { t.Fatal("3") })
t.Run("fourth test", func(t *testing.T) { t.Fatal("4") })
}
一个套件的示例输出:
therealplato/stack-suites Ω go test -run TestSuite1
--- FAIL: TestSuite1 (0.00s)
--- FAIL: TestSuite1/first_test (0.00s)
--- FAIL: TestSuite1/second_test (0.00s)
FAIL
exit status 1
FAIL github.com/therealplato/stack-suites 0.005s
一个测试的输出示例:
therealplato/stack-suites Ω go test -run TestSuite2/third
--- FAIL: TestSuite2 (0.00s)
--- FAIL: TestSuite2/third_test (0.00s)
main_test.go:11: 3
FAIL
exit status 1
FAIL github.com/therealplato/stack-suites 0.005s