インストール
$go get -u github.com/cweill/gotests/...
复制代码
の使用の具体的な例
使い方
$gotests [options] PATH ...
复制代码
オプション説明
-all generate go tests for all functions and methods
-excl regexp. generate go tests for functions and methods that don't match. Takes precedence over -only, -exported, and -all -exported generate go tests for exported functions and methods. Takes precedence over -only and -all -i print test inputs in error messages -only regexp. generate go tests for functions and methods that match only.Takes precedence over -all -w write output to (test) files instead of stdout -nosubtests disable subtest generation. Only available for Go 1.7+ -template_dir optional. Path to a directory containing custom test code templates 复制代码
- すべての機能および方法ソースファイルのテストを生成する方法
$gotests -all -w -i XXX.go
复制代码
- 単一の試験方法の生成方法
$gotests -w -only ^XXX$ PATH
复制代码
IDEで使用されます
- goland
ショートカットはCtrl + Shift + Tは、テストケースを生成するために、その後の選択、ファイル、パッケージの生成]を選択して、右後藤TESTかもしれ勝ちます。
-
vscode
機能テスト用のテストメソッドを生成するためのuintテストを生成:右に行く方法選択したファイルは、Go]を選択します。
著者:yuyongboの
リンクします。https://juejin.im/post/5bce9a2d5188250cf316bbf5
出典:ナゲッツ