A simple yet intuitive golang unit test framework.

Overview

gotest

Intuitive and simple golang testing framework which helps in writing unit tests in a way which improves the readability of the test.

Here is an example unit test which demonstrate the easy and intuitive way of writing unit test.

package test

import (
	. "github.com/wishbee/gotest"
	"testing"
)

type SomeDataToBeUnitTested struct {
	id int
}
func (t *SomeDataToBeUnitTested)SetId(i int) {
	t.id = i
}
func (t *SomeDataToBeUnitTested)Id() int {
	return t.id
}

func TestScenario(t *testing.T) {
	scenario := NewScenario(t)
	v := &SomeDataToBeUnitTested{}
	scenario.When("I set the Id as 4", func(and And, then Then) {
		v.SetId(4)
		then.AssertEqual(4, v.Id())
		and.I("reset Id as 5", func(and And, then Then) {
			v.SetId(5)
			then.AssertEqual(5, v.Id())
			then.Logln("Some information logging...")
			// ...
			// ...
			then.Logln("Some more informational logging")
		})
		and.I("reset Id again to 0", func(and And, then Then) {
			v.SetId(0)
			then.Logln("Then value of Id should be 0")
			then.AssertEqual(0,v.Id())
		})
	})

}

Below is the output from above unit test.

=== RUN   TestScenario
When I set the Id as 4
    Then I expect the value should be equal to 4
    And I reset Id as 5
        Then I expect the value should be equal to 5
        Some information logging...
        Some more informational logging
    And I reset Id again to 0
        Then value of Id should be 0
        Then I expect the value should be equal to 0
--- PASS: TestWhen (0.00s)
PASS

Process finished with exit code 0
You might also like...
A mock of Go's net package for unit/integration testing

netmock: Simulate Go network connections netmock is a Go package for simulating net connections, including delays and disconnects. This is work in pro

How we can run unit tests in parallel mode with failpoint injection taking effect and without injection race

This is a simple demo to show how we can run unit tests in parallel mode with failpoint injection taking effect and without injection race. The basic

Go Unit Testing Clean Arch

Golang Unit Testing Tutorial melakukan unit testing di Golang yang sudah menerapkan clean architecture Menjalankan Service PSQL_HOST=IP Database Serv

Vault mock - Mock of Hashicorp Vault used for unit testing

vault_mock Mock of Hashicorp Vault used for unit testing Notice This is a person

End to end functional test and automation framework
End to end functional test and automation framework

Declarative end to end functional testing (endly) This library is compatible with Go 1.12+ Please refer to CHANGELOG.md if you encounter breaking chan

http integration test framework

go-hit hit is an http integration test framework written in golang. It is designed to be flexible as possible, but to keep a simple to use interface f

Microservice Test Framework

This Microservice Test Framework (MTF) allows in simple way to mock service dependencies and setup docker test environment comprehensive.

Full-featured test framework for Go! Assertions, mocking, input testing, output capturing, and much more! 🍕
Full-featured test framework for Go! Assertions, mocking, input testing, output capturing, and much more! 🍕

testza 🍕 Testza is like pizza for Go - you could life without it, but why should you? Get The Module | Documentation | Contributing | Code of Conduct

Testy is a Go test running framework designed for Gametime's API testing needs.

template_library import "github.com/gametimesf/template_library" Overview Index Overview Package template_library is a template repository for buildin

Owner
null
Belajar golang unit test

perintah eksekusi di root folder : go test -v ./... assertion ambil dari framewo

Dhany 0 Feb 3, 2022
Easier way to unit test terraform

Unit testing terraform (WIP) Disclaimer Currently, the only way to compare values is using JSON query path and all types are strings. want := terraf

Thiago Nache Carvalho 51 Aug 16, 2022
Benchmarking deferent Fibonacci functions and algorithms with running unit test

GoFibonacciBench Benchmarking deferent Fibonacci functions and algorithms with running unit test ... Introduction: Fibonacci numbers are special kinds

null 2 Feb 27, 2022
Test-assignment - Test assignment with golang

test-assignment We have a two steam of data and we need to save it in the map: I

null 0 Jan 19, 2022
Simple HTTP integration test framework for Golang

go-itest Hassle-free REST API testing for Go. Installation go get github.com/jefflinse/go-itest Usage Create tests for your API endpoints and run the

Jeff Linse 12 Jan 8, 2022
go-test-trace is like go test but it also generates distributed traces.

go-test-trace go-test-trace is like go test but it also generates distributed traces. Generated traces are exported in OTLP to a OpenTelemetry collect

JBD 376 Jan 5, 2023
Flugel Test Documentation for steps to run and test the automatio

Flugel Test Documentation Documentation for steps to run and test the automation #Test-01 1 - Local Test Using Terratest (End To End) 1- By runing " t

Suc0_Unix 0 Nov 13, 2022
go websocket client for unit testing of a websocket handler

wstest A websocket client for unit-testing a websocket server The gorilla organization provides full featured websocket implementation that the standa

Eyal Posener 98 Dec 21, 2022
gostub is a library to make stubbing in unit tests easy

gostub gostub is a library to make stubbing in unit tests easy. Getting started Import the following package: github.com/prashantv/gostub Click here t

Prashant Varanasi 265 Dec 28, 2022
gomonkey is a library to make monkey patching in unit tests easy

gomonkey is a library to make monkey patching in unit tests easy, and the core idea of monkey patching comes from Bouke, you can read this blogpost for an explanation on how it works.

Zhang Xiaolong 1.4k Jan 4, 2023