Generate Go tests from your source code.
Clone or download
cweill Merge pull request #52 from s-kostyaev/add-new-emacs-extention
Add go-gen-test Emacs extension (MELPA) to Readme.
Latest commit 97d0977 May 20, 2018

gotests License godoc Build Status Coverage Status codebeat badge Go Report Card

gotests makes writing Go tests easy. It's a Golang commandline tool that generates table driven tests based on its target source files' function and method signatures. Any new dependencies in the test files are automatically imported.


The following shows gotests in action using the official Sublime Text 3 plugin. Plugins also exist for Emacs, also Emacs, Vim, Atom Editor, and Visual Studio Code.



Minimum Go version: Go 1.6

Use go get to install and update:

$ go get -u


From the commandline, gotests can generate Go tests for specific source files or an entire directory. By default, it prints its output to stdout.

$ gotests [options] PATH ...

Available options:

  -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


Contributing guidelines are in


gotests is released under the Apache 2.0 License.