installation
$go get -u github.com/cweill/gotests/...
复制代码
Specific examples of the use of
usage
$gotests [options] PATH ...
复制代码
options Description
-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 复制代码
- The method of generating a test for all functions and methods source file
$gotests -all -w -i XXX.go
复制代码
- The method of generating a test method for a single
$gotests -w -only ^XXX$ PATH
复制代码
Used in the IDE
- goland
Win the shortcut ctrl + shift + T, may be right-goto TEST, select Generate for selection, file, package and then to generate test cases.
-
vscode
Right-go method selected file select Go: Generate Uint Tests For Function to generate a test method for testing.
Author: yuyongbo
link: https: //juejin.im/post/5bce9a2d5188250cf316bbf5
Source: Nuggets