goteststool

Automatically generate test files and test methods

Github.com/cweill/gote…

The installation

$go get -u github.com/cweill/gotests/...
Copy the code

Usage Examples

usage

$gotests [options] PATH ...
Copy the code

The options that

-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 templatesCopy the code
  • Generates the test method for all functions and methods in the source file
$gotests -all -w -i XXX.go
Copy the code
  • Generate the test method for a single method
$gotests -w -only ^XXX$ PATH
Copy the code

Use under IDE

  • goland

In Win, shortcut keys CTRL + Shift +T or right mouse button goto TEST and select Generate for Selection, file, package to Generate TEST cases.

  • vscode

    Select the method in the go file and right-click go :Generate Uint Tests For Function to Generate the test method.

Recommend the article

Docker cloud platform Go language unit testing practice

5 advanced testing techniques in Go

Unit testing and interfaces

Go unit testing, benchmark testing, HTTP testing

Go test, go test tool specific command flag

Using Subtests and Sub-benchmarks

How to use Subtests and sub-benchmarks

Go test is a lesser-known feature