Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hexdigest/gounit

Unit tests generator for Go programming language
https://github.com/hexdigest/gounit

generator go golang unit-testing

Last synced: about 1 month ago
JSON representation

Unit tests generator for Go programming language

Awesome Lists containing this project

README

        

# GoUnit [![License](https://img.shields.io/badge/license-Apache%202.0-green.svg)](https://github.com/hexdigest/gounit/blob/master/LICENSE) [![Build Status](https://travis-ci.org/hexdigest/gounit.svg?branch=master)](https://travis-ci.org/hexdigest/gounit) [![Coverage Status](https://coveralls.io/repos/github/hexdigest/gounit/badge.svg?branch=master)](https://coveralls.io/github/hexdigest/gounit?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/hexdigest/gounit)](https://goreportcard.com/report/github.com/hexdigest/gounit) [![GoDoc](https://godoc.org/github.com/hexdigest/gounit?status.svg)](http://godoc.org/github.com/hexdigest/gounit)

GoUnit is a commandline tool that generates tests stubs based on source function or method signature.

There are plugins for
* [Vim](https://github.com/hexdigest/gounit-vim)
* [Emacs](https://github.com/hexdigest/GoUnit-Emacs)
* [Atom](https://github.com/hexdigest/atom-gounit)
* [Sublime](https://github.com/hexdigest/gounit-sublime)

## Demo

![demo](https://github.com/hexdigest/gounit-vim/blob/master/demo.gif)

## Installation

```
go get -u github.com/hexdigest/gounit/cmd/gounit
```

## Usage of 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

## Custom test templates

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](https://github.com/hexdigest/gounit/blob/master/templates/minimock) 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](https://github.com/gojuno/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.

## Integration with editors and IDEs

To ease an integration of GoUnit with IDEs "gen" subcommand has a "-json" flag.
When -json flag is passed GoUnit reads [JSON requests](https://github.com/hexdigest/gounit/blob/master/client.go#L5) from Stdin in a loop and produces [JSON responses](https://github.com/hexdigest/gounit/blob/master/client.go#L16) 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.