Unit tests generator for Go programming language

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.

Owner
Max Chechel
Program or be programmed
Max Chechel
Similar Resources

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

Nov 12, 2021

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

Nov 14, 2021

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

Dec 30, 2022

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

Jun 13, 2022

🎅 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

Dec 28, 2022

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

Dec 6, 2021

Gec is a minimal stack-based programming language

Gec is a minimal stack-based programming language

Sep 18, 2022

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

Oct 3, 2022

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

Jan 1, 2023
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()
    }
    
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

Dec 2, 2021
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

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

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

Dec 22, 2021
The Gorilla Programming Language
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

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

Elastic is an Elasticsearch client for the Go programming language.

Jan 9, 2023
👩🏼‍💻A simple compiled programming language
👩🏼‍💻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

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.

Dec 24, 2022
Http web frame with Go Programming Language

Http web frame with Go Programming Language

Oct 17, 2021