Unit tests generator for Go programming language

Overview

GoUnit License Build Status Coverage Status Go Report Card GoDoc

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

There are plugins for

Demo

demo

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

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

You might also like...
A modern programming language written in Golang.

MangoScript A modern programming language written in Golang. Here is what I want MangoScript to look like: struct Rectangle { width: number he

A stack oriented esoteric programming language inspired by poetry and forth

paperStack A stack oriented esoteric programming language inspired by poetry and forth What is paperStack A stack oriented language An esoteric progra

Oak is an expressive, dynamically typed programming language

Oak 🌳 Oak is an expressive, dynamically typed programming language. It takes the best parts of my experience with Ink, and adds what I missed and rem

Besten programming language

Besten What holds this repository? Besten Lexer Besten Parser Besten Interpreter Besten Module Loader Besten Lexer Located in ./internal/lexer A set o

🎅 A programming language for Advent of Code.

🎅 Adventlang My blog post: Designing a Programming Language for Advent of Code A strongly typed but highly dynamic programming language interpreter w

An experimental programming language.

crank-lang An experimental & interpreted programming language written in Go. Features C like syntax Written in Golang Interpreted Statically Typed Dis

Gec is a minimal stack-based programming language

Gec is a minimal stack-based programming language

Random fake data and struct generator for Go.

Faker Random fake data and struct generator for Go. More than 100 generator functions Struct generator Unique data generator Builtin types support Eas

Random fake data generator written in go
Random fake data generator written in go

Gofakeit Random data generator written in go Features 160+ Functions!!! Concurrent Global Rand Struct Generator Custom Functions Http Server Command L

Comments
  • $func.TestName generates names that go vet rejects for non exported types.

    $func.TestName generates names that go vet rejects for non exported types.

    For non exported function like foo.bar, $func.TestName generates Testfoo_bar which go vet gives a warning about. Please change this to generate a name that is acceptable,. For example, an underscore could be inserted there, so the name becomes Test_foo. Thanks!

    This snippet could be a possible fix:

    //TestName returns a name of the test
    func (f *Func) TestName() string {
    	name := "Test"
    
    	if f.IsMethod() {
    		recvType := f.ReceiverType()
    		var ident *ast.Ident
    		if star, ok := recvType.(*ast.StarExpr); ok {
    			ident = star.X.(*ast.Ident)
    		} else {
    			ident = recvType.(*ast.Ident)
    		}
    		if !ident.IsExported() {
    			name += "_"
    		}
    		name += ident.String()
    		name += "_"
    	} else if !f.Signature.Name.IsExported() {
    		name += "_"
    	}
    
    	return name + f.Signature.Name.String()
    }
    
    opened by bjoerndemeyer 0
Owner
Max Chechel
Program or be programmed
Max Chechel
Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.

Advent of Code 2021 Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved

Kemal Ogun Isik 0 Dec 2, 2021
Zach Howell 0 Jan 4, 2022
A simple Via CEP Wrapper to demonstrate GoLang tests usage

via-cep-wrapper A simple Via CEP Wrapper to demonstrate GoLang tests usage Purpose Demonstrate how struct services could make easy to build and test a

Bruno 3 May 18, 2022
FreeSWITCH Event Socket library for the Go programming language.

eventsocket FreeSWITCH Event Socket library for the Go programming language. It supports both inbound and outbound event socket connections, acting ei

Alexandre Fiori 110 Dec 11, 2022
Simple interface to libmagic for Go Programming Language

File Magic in Go Introduction Provides simple interface to libmagic for Go Programming Language. Table of Contents Contributing Versioning Author Copy

Krzysztof Wilczyński 12 Dec 22, 2021
The Gorilla Programming Language

Gorilla Programming Language Gorilla is a tiny, dynamically typed, multi-engine programming language It has flexible syntax, a compiler, as well as an

null 29 Apr 16, 2022
Elastic is an Elasticsearch client for the Go programming language.

Elastic is an Elasticsearch client for the Go programming language.

Oliver Eilhard 7.1k Jan 9, 2023
👩🏼‍💻A simple compiled programming language

The language is written in Go and the target language is C. The built-in library is written in C too

paco 28 Nov 29, 2022
Lithia is an experimental functional programming language with an implicit but strong and dynamic type system.

Lithia is an experimental functional programming language with an implicit but strong and dynamic type system. Lithia is designed around a few core concepts in mind all language features contribute to.

Valentin Knabel 9 Dec 24, 2022
Http web frame with Go Programming Language

Http web frame with Go Programming Language

jk 0 Oct 17, 2021