我想为使用证言/套件的GO测试添加自定义标志.从这个thread看,它只能在TestMain()
(如果在GO 1.13之前是init()
).然而,对于证言/套房包,TestMain()
不是一个很好的 Select .我try 声明SeupSuite()
和TestMyTestSuite()
中的标志,它们似乎是对应的TestMain()
,但都返回了错误flag provided but not defined: -mycustomflag
.以下是示例代码.任何建议都将不胜感激!
我的测试.go :
package main
import (
"flag"
"fmt"
"github.com/stretchr/testify/suite"
"testing"
)
type MyTestSuite struct {
suite.Suite
}
func (suite *MyTestSuite) SetupSuite() {
flagBoolPtr := flag.Bool("mycustomflag", false, "this is a bool flag")
flag.Parse()
fmt.Printf("my flag is set to: %t", *flagBoolPtr)
}
func TestMyTestSuite(t *testing.T) {
// flagBoolPtr := flag.Bool("mycustomflag", false, "this is a bool flag")
// flag.Parse()
// fmt.Printf("my flag is set to: %t", *flagBoolPtr)
suite.Run(t, new(MyTestSuite))
}
func (suite *MyTestSuite) TestBuildClosure() {
fmt.Println("my test")
}
这是我使用的命令:
go test my_test.go -mycustomflag