0
0

More than 1 year has passed since last update.

goで特定のTestifyのテストをCLIで実行する例

Posted at

go test  \
    -timeout 120s \
    -tags mybuildtag \
    -run ^Test_MyTestSuite$ \
    -v -test.v \
    github.com/my-org/my-project/mypkg \
    -testify.m ^\(Test_MyFuncTest\)$

ポイント

  • -testify.m ...フラグはパッケージより後に置く
  • 正規表現の内容によっては必要に応じて中身をエスケープする
    • ここでは()カッコはエスケープする

Story

VSCodeのOutputに騙された

いつもVSCodeのrun testをクリックしてテストを実行していましたが、CLIで実行したい場面があり、
VSCodeのOutputビューに出力されるコマンドをコピペしたところうまくテストが実行されず。
結局試行錯誤してヘルプ見て解決。

テストバイナリ向けのフラグはパッケージより後に渡す

ヘルプによれば、ビルドフラグ、テストフラグはパッケージ指定より前でも後でも良いが、テストバイナリフラグはパッケージより後に渡さないといけない模様。

$ go help test
usage: go test [build/test flags] [packages] [build/test flags & test binary flags]

ということで、-testify.m ^\(Test_MyFuncTest\)$はTestifyに渡すフラグということで、テストバイナリ用のフラグであるため、パッケージ指定より後に渡すべし。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0