gotests

package module
v1.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

README

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 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

Contributions

Contributing guidelines are in CONTRIBUTING.md.

License

gotests is released under the Apache 2.0 License.

Documentation

Overview

Package gotests contains the core logic for generating table-driven tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GeneratedTest

type GeneratedTest struct {
	Path      string             // The test file's absolute path.
	Functions []*models.Function // The functions with new test methods.
	Output    []byte             // The contents of the test file.
}

A GeneratedTest contains information about a test file with generated tests.

func GenerateTests

func GenerateTests(srcPath string, opt *Options) ([]*GeneratedTest, error)

GenerateTests generates table-driven tests for the function and method signatures defined in the target source path file(s). The source path parameter can be either a Go source file or directory containing Go files.

type Options

type Options struct {
	Only        *regexp.Regexp        // Includes only functions that match.
	Exclude     *regexp.Regexp        // Excludes functions that match.
	Exported    bool                  // Include only exported methods
	PrintInputs bool                  // Print function parameters in error messages
	Subtests    bool                  // Print tests using Go 1.7 subtests
	Importer    func() types.Importer // A custom importer.
	TemplateDir string                // Path to custom template set
}

Options provides custom filters and parameters for generating tests.

Directories

Path Synopsis
A commandline tool for generating table-driven Go tests.
A commandline tool for generating table-driven Go tests.
process
Package process is a thin wrapper around the gotests library.
Package process is a thin wrapper around the gotests library.
internal
goparser
Package goparse contains logic for parsing Go files.
Package goparse contains logic for parsing Go files.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL