GoUnit is a commandline tool that generates tests stubs based on source function or method signature.
There are plugins for
go get -u github.com/hexdigest/gounit/cmd/gounit
This will generate test stubs for all functions and methods in file.go
$ gounit gen -i file.go
Run gounit help
for more options
If you're not satisfied with the code produced by the default GoUnit test template you can always write your own! You can use minimock template as an example. Here is how to add and switch to the custom template:
$ curl https://raw.githubusercontent.com/hexdigest/gounit/master/templates/minimock > minimock
$ gounit template add minimock
$ gounit template list
gounit templates installed
* default
minimock
$ gounit template use minimock
Minimock template produces test stubs that are aware of the mocks generated by the minimock mock generator. By using both of these tools you can automate the process of writing tests and focus on your test cases rather than routine operations.
To ease an integration of GoUnit with IDEs "gen" subcommand has a "-json" flag. When -json flag is passed GoUnit reads JSON requests from Stdin in a loop and produces JSON responses with generated test(s) that are written to Stdout. Using this mode you can generate as many tests as you want by running GoUnit executable only once.