All Projects → smartystreets → Gunit

smartystreets / Gunit

Licence: other
xUnit-style test fixture adapter for go test

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Gunit

main
Mocks Server monorepo
Stars: ✭ 109 (+15.96%)
Mutual labels:  fixtures, testing-tools
Beanmother
A library for setting up Java objects as test data.
Stars: ✭ 102 (+8.51%)
Mutual labels:  testing-tools, fixtures
Mockwebserverplus
✔️ OkHttp mockwebserver with fixtures extension
Stars: ✭ 87 (-7.45%)
Mutual labels:  testing-tools, fixtures
Pytest Mimesis
Mimesis integration with the pytest test runner. This plugin provider useful fixtures based on providers from Mimesis.
Stars: ✭ 46 (-51.06%)
Mutual labels:  testing-tools, fixtures
Testcl
when you don't have the balls to test your F5 BIG-IP iRules directly in production
Stars: ✭ 79 (-15.96%)
Mutual labels:  testing-tools
Reportportal
Main Repository. Report Portal starts here - see readme below.
Stars: ✭ 1,175 (+1150%)
Mutual labels:  testing-tools
Expect Playwright
Jest utility matcher functions to simplify expect statements for the usage with Playwright.
Stars: ✭ 66 (-29.79%)
Mutual labels:  testing-tools
Wp Cli Fixtures
Easily generate custom fake data for WordPress
Stars: ✭ 65 (-30.85%)
Mutual labels:  fixtures
Courtney
Courtney is a coverage tool for Go
Stars: ✭ 92 (-2.13%)
Mutual labels:  testing-tools
Conventional
A suite of convention specifications for enforcing type and style conventions in your codebase
Stars: ✭ 85 (-9.57%)
Mutual labels:  testing-tools
Babel Test
An opinionated library to make testing babel plugins easier.
Stars: ✭ 79 (-15.96%)
Mutual labels:  fixtures
System tester
A Development Tool for creating and managing system tests for Ruby on Rails >= 5.1 Applications
Stars: ✭ 73 (-22.34%)
Mutual labels:  testing-tools
Testcafe
A Node.js tool to automate end-to-end web testing.
Stars: ✭ 9,176 (+9661.7%)
Mutual labels:  testing-tools
Assert
A collection of convenient assertions for Swift testing
Stars: ✭ 69 (-26.6%)
Mutual labels:  testing-tools
Testdouble.js
A minimal test double library for TDD with JavaScript
Stars: ✭ 1,214 (+1191.49%)
Mutual labels:  testing-tools
Meissa
Cross-platform Distributed Test Runner. Executes tests in parallel, time balanced on multiple machines.
Stars: ✭ 66 (-29.79%)
Mutual labels:  testing-tools
Snapper
Bringing Jest-esque Snapshot testing to C#
Stars: ✭ 85 (-9.57%)
Mutual labels:  testing-tools
Awesome K6
A curated list of resources on automated load- and performance testing using k6 🗻
Stars: ✭ 78 (-17.02%)
Mutual labels:  testing-tools
Vscode Catch2 Test Adapter
Catch2, Google Test and doctest Adapter for the VSCode
Stars: ✭ 74 (-21.28%)
Mutual labels:  testing-tools
Perftools Runner
Google Performance Tools runner using Puppeteer
Stars: ✭ 79 (-15.96%)
Mutual labels:  testing-tools

Build Status Code Coverage Go Report Card GoDoc

gunit

Installation

$ go get github.com/smartystreets/gunit

We now present gunit, yet another testing tool for Go.

Not again... (GoConvey was crazy enough...but sort of cool, ok I'll pay attention...)

No wait, this tool has some very interesting properties. It's a mix of good things provided by the built-in testing package, the assertions you know and love from the GoConvey project, the xUnit testing style (the first real unit testing framework), and it's all glued together with go test.

Blah, blah, yeah, yeah. Ok, so what's wrong with just using the standard "testing" package? What's better about this gunit thing?

The convention established by the "testing" package and the go test tool only allows for local function scope:

func TestSomething(t *testing.T) {
	// blah blah blah
}

This limited scope makes extracting functions or structs inconvenient as state will have to be passed to such extractions or state returned from them. It can get messy to keep a test nice and short. Here's the basic idea of what the test author using gunit would implement in a *_test.go file:


package examples

import (
    "time"
	"testing"

	"github.com/smartystreets/assertions/should"
	"github.com/smartystreets/gunit"
)

func TestExampleFixture(t *testing.T) {
	gunit.Run(new(ExampleFixture), t)
}

type ExampleFixture struct {
	*gunit.Fixture // Required: Embedding this type is what makes the magic happen.

	// Declare useful state here (probably the stuff being tested, any fakes, etc...).
}

func (this *ExampleFixture) SetupStuff() {
	// This optional method will be executed before each "Test"
	// method (because it starts with "Setup").
}
func (this *ExampleFixture) TeardownStuff() {
	// This optional method will be executed after each "Test"
	// method (because it starts with "Teardown"), even if the test method panics.
}


// This is an actual test case:
func (this *ExampleFixture) TestWithAssertions() {
	// Here's how to use the functions from the `should`
	// package at github.com/smartystreets/assertions/should
	// to perform assertions:
	this.So(42, should.Equal, 42)
	this.So("Hello, World!", should.ContainSubstring, "World")
}

func (this *ExampleFixture) SkipTestWithNothing() {
	// Because this method's name starts with 'Skip', it will be skipped.
}

func (this *ExampleFixture) LongTestSlowOperation() {
	// Because this method's name starts with 'Long', it will be skipped if `go test` is run with the `short` flag.
	time.Sleep(time.Hour)
	this.So(true, should.BeTrue)
}

So, I see just one traditional test function and it's only one line long. What's the deal with that?

Astute observations. gunit allows the test author to use a struct as the scope for a group of related test cases, in the style of xUnit fixtures. This makes extraction of setup/teardown behavior (as well as invoking the system under test) much simpler because all state for the test can be declared as fields on a struct which embeds the Fixture type from the gunit package. All you have to do is create a Test function and pass a new instance of your fixture struct to gunit's Run function along with the *testing.T and it will run all defined Test methods along with the Setup and Teardown method.

Enjoy.

Parallelism

By default all fixtures are run in parallel as they should be independent, but if you for some reason have fixtures which need to be run sequentially, you can change the Run() method to RunSequential(), e.g. in the above example

func TestExampleFixture(t *testing.T) {
	gunit.RunSequential(new(ExampleFixture), t)
}

Advanced Examples


For users of JetBrains IDEs, here's LiveTemplate you can use for generating the scaffolding for a new fixture:

  • Abbreviation: fixture
  • Description: Generate gunit Fixture boilerplate
  • Template Text:
func Test$NAME$(t *testing.T) {
    gunit.Run(new($NAME$), t)
}

type $NAME$ struct {
    *gunit.Fixture
}

func (this *$NAME$) Setup() {
}

func (this *$NAME$) Test$END$() {
}

Be sure to specify that this LiveTemplate is applicable in Go files.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].