gotests

从您的源代码中自动生成 Go 测试模板。「Generate Go tests from your source code.」

Github stars Tracking Chart

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.

Demo

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

demo

Installation

Minimum Go version: Go 1.6

Use go get to install and update:

$ go get -u github.com/cweill/gotests/...

Usage

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 tests for all functions and methods

  -excl                 regexp. generate tests for functions and methods that don't
                         match. Takes precedence over -only, -exported, and -all

  -exported             generate tests for exported functions and methods. Takes
                         precedence over -only and -all

  -i                    print test inputs in error messages

  -only                 regexp. generate tests for functions and methods that match only.
                         Takes precedence over -all

  -nosubtests           disable subtest generation when >= Go 1.7

  -w                    write output to (test) files instead of stdout

  -template_dir         Path to a directory containing custom test code templates. Takes
                         precedence over -template

  -template             Specify custom test code templates, e.g. testify

  -template_params_file read external parameters to template by json with file

  -template_params      read external parameters to template by json with stdin

Contributions

Contributing guidelines are in CONTRIBUTING.md.

License

gotests is released under the Apache 2.0 License.

Main metrics

Overview
Name With Ownercweill/gotests
Primary LanguageGo
Program languageGo (Language Count: 2)
PlatformLinux, Mac, Windows
License:Apache License 2.0
所有者活动
Created At2016-01-19 13:06:02
Pushed At2025-10-31 02:15:01
Last Commit At2025-10-24 01:20:04
Release Count18
Last Release Namev1.9.0 (Posted on 2025-10-28 01:54:38)
First Release Namev1.0-beta (Posted on )
用户参与
Stargazers Count5.2k
Watchers Count78
Fork Count347
Commits Count424
Has Issues Enabled
Issues Count102
Issue Open Count33
Pull Requests Count56
Pull Requests Open Count5
Pull Requests Close Count35
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private