{"id":13694167,"url":"https://github.com/smarty/gunit","last_synced_at":"2025-12-26T10:31:36.483Z","repository":{"id":30204112,"uuid":"33755045","full_name":"smarty/gunit","owner":"smarty","description":"xUnit-style test fixture adapter for go test","archived":false,"fork":false,"pushed_at":"2023-10-24T20:59:42.000Z","size":256,"stargazers_count":116,"open_issues_count":1,"forks_count":10,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-04-11T14:21:01.416Z","etag":null,"topics":["fixtures","go","gunit","tdd-utilities","testing-tools","xunit-frameworks"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smarty.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-04-10T23:24:04.000Z","updated_at":"2024-04-10T17:35:49.000Z","dependencies_parsed_at":"2023-09-02T23:44:34.820Z","dependency_job_id":"cf00dc01-9c83-46a0-adb4-97e3c00231a9","html_url":"https://github.com/smarty/gunit","commit_stats":null,"previous_names":["smarty/gunit","smartystreets/gunit"],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smarty%2Fgunit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smarty%2Fgunit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smarty%2Fgunit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smarty%2Fgunit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smarty","download_url":"https://codeload.github.com/smarty/gunit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224346347,"owners_count":17296200,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fixtures","go","gunit","tdd-utilities","testing-tools","xunit-frameworks"],"created_at":"2024-08-02T17:01:25.822Z","updated_at":"2025-12-26T10:31:36.477Z","avatar_url":"https://github.com/smarty.png","language":"Go","funding_links":[],"categories":["Open source library"],"sub_categories":["Test"],"readme":"#### SMARTY DISCLAIMER: Subject to the terms of the associated license agreement, this software is freely available for your use. This software is FREE, AS IN PUPPIES, and is a gift. Enjoy your new responsibility. This means that while we may consider enhancement requests, we may or may not choose to entertain requests at our sole and absolute discretion.\n\n\n# gunit\n\n[![GoDoc](https://godoc.org/github.com/smarty/gunit?status.svg)](http://godoc.org/github.com/smarty/gunit)\n\nInstallation:\n\n```\n$ go get github.com/smarty/gunit\n```\n\n-------------------------\n\nWe now present `gunit`, yet another testing tool for Go.\n\n\u003e Not again... ([GoConvey](http://goconvey.co) was crazy enough...but sort of cool, ok I'll pay attention...)\n\nNo wait, this tool has some very interesting properties. It's a mix of good things provided by the built-in testing package, the [assertions](https://github.com/smarty/assertions) you know and love from the [GoConvey](http://goconvey.co) project, the [xUnit](https://en.wikipedia.org/wiki/XUnit) testing style (the first real unit testing framework), and it's all glued together with `go test`.\n\n\u003e Blah, blah, yeah, yeah. Ok, so what's wrong with just using the standard \"testing\" package? What's better about this `gunit` thing?\n\nThe convention established by the \"testing\" package and the `go test` tool only allows for local function scope:\n\n```\nfunc TestSomething(t *testing.T) {\n\t// blah blah blah\n}\n```\n\nThis 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:\n\n```go\n\npackage examples\n\nimport (\n    \"time\"\n\t\"testing\"\n\n\t\"github.com/smarty/gunit/\"\n\t\"github.com/smarty/gunit/assert/should\"\n)\n\nfunc TestExampleFixture(t *testing.T) {\n\tgunit.Run(new(ExampleFixture), t)\n}\n\ntype ExampleFixture struct {\n\t*gunit.Fixture // Required: Embedding this type is what makes the magic happen.\n\n\t// Declare useful state here (probably the stuff being tested, any fakes, etc...).\n}\n\nfunc (this *ExampleFixture) SetupStuff() {\n\t// This optional method will be executed before each \"Test\"\n\t// method (because it starts with \"Setup\").\n}\nfunc (this *ExampleFixture) TeardownStuff() {\n\t// This optional method will be executed after each \"Test\"\n\t// method (because it starts with \"Teardown\"), even if the test method panics.\n}\n\n\n// This is an actual test case:\nfunc (this *ExampleFixture) TestWithAssertions() {\n\t// Here's how to use the functions from the `should`\n\t// package at github.com/smarty/assertions/should\n\t// to perform assertions:\n\tthis.So(42, should.Equal, 42)\n\tthis.So(\"Hello, World!\", should.ContainSubstring, \"World\")\n}\n\nfunc (this *ExampleFixture) SkipTestWithNothing() {\n\t// Because this method's name starts with 'Skip', it will be skipped.\n}\n\nfunc (this *ExampleFixture) LongTestSlowOperation() {\n\t// Because this method's name starts with 'Long', it will be skipped if `go test` is run with the `short` flag.\n\ttime.Sleep(time.Hour)\n\tthis.So(true, should.BeTrue)\n}\n```\n\n-------------------------\n\n\u003e So, I see just one traditional test function and it's only one line long. What's the deal with that?\n\nAstute 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](https://en.wikipedia.org/wiki/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.\n\nEnjoy.\n\n### Parallelism\nBy 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\n\n```go\nfunc TestExampleFixture(t *testing.T) {\n\tgunit.RunSequential(new(ExampleFixture), t)\n}\n```\n\n[Advanced Examples](https://github.com/smarty/gunit/tree/master/advanced_examples)\n\n----------------------------------------------------------------------------\n\nFor users of JetBrains IDEs, here's LiveTemplate you can use for generating the scaffolding for a new fixture:\n\n- Abbreviation: `fixture`\n- Description: `Generate gunit Fixture boilerplate`\n- Template Text:\n\n```\nfunc Test$NAME$Fixture(t *testing.T) {\n    gunit.Run(new($NAME$Fixture), t)\n}\n\ntype $NAME$Fixture struct {\n    *gunit.Fixture\n}\n\nfunc (this *$NAME$Fixture) Setup() {\n}\n\nfunc (this *$NAME$Fixture) Test$END$() {\n}\n\n```\n\nBe sure to specify that this LiveTemplate is applicable in Go files.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmarty%2Fgunit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmarty%2Fgunit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmarty%2Fgunit/lists"}