{"id":21481614,"url":"https://github.com/arikkfir/justest","last_synced_at":"2025-09-10T07:40:19.149Z","repository":{"id":237994779,"uuid":"795452843","full_name":"arikkfir/justest","owner":"arikkfir","description":"Go testing framework with extra sugar!","archived":false,"fork":false,"pushed_at":"2025-01-06T22:53:28.000Z","size":87,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-23T18:49:32.010Z","etag":null,"topics":["go","go-lib","go-library","go-libs","go-test","go-testing","golang","golang-lib","golang-libraries","golang-library","testing"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arikkfir.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"arikkfir"}},"created_at":"2024-05-03T10:08:39.000Z","updated_at":"2024-06-23T13:43:48.000Z","dependencies_parsed_at":"2024-11-23T12:37:42.200Z","dependency_job_id":null,"html_url":"https://github.com/arikkfir/justest","commit_stats":null,"previous_names":["arikkfir/justest"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arikkfir%2Fjustest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arikkfir%2Fjustest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arikkfir%2Fjustest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arikkfir%2Fjustest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arikkfir","download_url":"https://codeload.github.com/arikkfir/justest/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244006394,"owners_count":20382443,"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":["go","go-lib","go-library","go-libs","go-test","go-testing","golang","golang-lib","golang-libraries","golang-library","testing"],"created_at":"2024-11-23T12:27:32.097Z","updated_at":"2025-03-17T09:14:27.543Z","avatar_url":"https://github.com/arikkfir.png","language":"Go","funding_links":["https://github.com/sponsors/arikkfir"],"categories":[],"sub_categories":[],"readme":"# justest\n\n![Maintainer](https://img.shields.io/badge/maintainer-arikkfir-blue)\n![GoVersion](https://img.shields.io/github/go-mod/go-version/arikkfir/justest.svg)\n[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)](https://godoc.org/github.com/arikkfir/justest)\n[![GoReportCard](https://goreportcard.com/badge/github.com/arikkfir/justest)](https://goreportcard.com/report/github.com/arikkfir/justest)\n\n\u003e Go testing framework with extra sugar\n\nThis Go testing framework has the following goals:\n\n* Play nice with `go test`\n* Provide a fluent API for making assertions\n* Provide a succinct yet informative error information on failures\n* Make testing easier to read and write\n\n## Attribution\n\nThis library is **heavily** inspired by [Gomega](https://github.com/onsi/gomega)\nand [Ginkgo](https://github.com/onsi/ginkgo),\ntwo **excellent** Go testing libraries that I've used extensively in the past. If you need a full **standalone** (see\nbelow)\nBDD testing framework, those are highly recommended.\n\nThe reason Justest was created is because Gomega and Ginkgo do not play great with `go test` (though Gomega does have a\n`go test` integration, it's still primarily meant to be used with Ginkgo) whereas Justest is meant all along to be used\nwith `go test`.\n\n## Usage\n\n```go\npackage my_test\n\nimport (\n\t\"fmt\"\n\t\"regexp\"\n\t\"testing\"\n\t\"time\"\n\n\t. \"github.com/arikkfir/justest\"\n)\n\nfunc TestSomething(t *testing.T) {\n\t\n\t// Simple assertions\n\tWith(t).VerifyThat(1).Will(BeBetween(0, 2)).Now()\n\tWith(t).VerifyThat(\"\").Will(BeEmpty()).Now()\n\tWith(t).VerifyThat([]int{1, 2, 3}).Will(BeEmpty()).Now() // \u003c-- This will fail!\n\tWith(t).VerifyThat(1).Will(BeGreaterThan(0)).Now()\n\tWith(t).VerifyThat(1).Will(BeLessThan(2)).Now()\n\tWith(t).VerifyThat(\"abc\").Will(BeNil()).Now() // \u003c-- This will fail!\n\tWith(t).VerifyThat(1).Will(EqualTo(1)).Now()\n\tWith(t).VerifyThat(\"abc\").Will(EqualTo(\"def\")).Now() // \u003c-- This will fail!\n\n\t// Assert success or failure of a function (functions can have any set of return values or none at all)\n\tsucceedingFunc := func() (string, error) { return \"abc\", nil }\n\tWith(t).VerifyThat(succeedingFunc).Will(Succeed()).Now() // \u003c-- Will succeed since error return value is nil\n\tWith(t).VerifyThat(succeedingFunc).Will(Fail()).Now()    // \u003c-- Will fail since it expects error return value to be non-nil\n\tfailingFunc := func() (string, error) { return \"\", fmt.Errorf(\"error\") }\n\tWith(t).VerifyThat(failingFunc).Will(Succeed()).Now() // \u003c-- Will fail since error return value is not nil\n\tWith(t).VerifyThat(failingFunc).Will(Fail()).Now()    // \u003c-- Will succeed since it expects error return value to be non-nil\n\n\t// Assert negation of another assertion\n\tWith(t).VerifyThat(1).Will(Not(EqualTo(2))).Now()\n\t\n\t// Assert something will **eventually** match\n\t// It will stop when the function succeeds (no assertion failure) or when time runs out\n\tWith(t).VerifyThat(func(t T) {\n\n\t\t// Will be invoked every 100ms until either it no longer fails or until time runs out (10s)\n\t\tWith(t).VerifyThat(2).Will(EqualTo(2)).Now()\n\n\t}).Will(Succeed()).Within(10*time.Second, 100*time.Millisecond)\n\n\t// Assert something will **repeatedly** match for a certain amount of time\n\t// It will stop on the first time the function fails\n\tWith(t).VerifyThat(func(t T) {\n\n\t\t// Will be invoked every 100ms until either it fails or until time runs out (10s)\n\t\tWith(t).VerifyThat(2).Will(EqualTo(2)).Now()\n\n\t}).Will(Succeed()).For(10*time.Second, 100*time.Millisecond)\n\n\t// Assert on text patterns\n\tWith(t).VerifyThat(\"abc\").Will(Say(\"^a*c$\")).Now()\n\tWith(t).VerifyThat(\"abc\").Will(Say(regexp.MustCompile(\"^a*c$\"))).Now()\n\tWith(t).VerifyThat([]byte(\"abc\")).Will(Say(\"^a*c$\")).Now()\n}\n```\n\n## Custom matchers\n\nYou can easily create your own matchers by implementing the `Matcher` interface:\n\n```go\npackage my_test\n\nimport (\n\t\"reflect\"\n\n\t. \"github.com/arikkfir/justest\"\n)\n\nvar (\n\tmyValueExtractor = NewValueExtractor(ExtractSameValue)\n)\n\n// BeSuperDuper returns a matcher that will ensure that each actual value passed to \"With(t).VerifyThat(...)\" will be either\n// \"super duper\" or \"extra super duper\", depending on the value of the `extraDuper` parameter.\nfunc BeSuperDuper(extraDuper bool) Matcher {\n\treturn MatcherFunc(func(t T, actuals ...any) {\n\t\tGetHelper(t).Helper()\n\t\tfor _, actual := range actuals {\n\t\t\tv := myValueExtractor.MustExtractValue(t, actual) // This is optional, but recommended, see value extraction below\n\t\t\tif extraDuper {\n\t\t\t\t// Fail if it's not EXTRA super-duper\n\t\t\t\tif v.(string) != \"extra super duper\" {\n\t\t\t\t\tt.Fatalf(\"Value '%s' is not extra super-duper!\", v)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Fail if it's not super-duper\n\t\t\t\tif v.(string) != \"super duper\" {\n\t\t\t\t\tt.Fatalf(\"Value '%s' is not super-duper!\", v)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t})\n}\n```\n\n## Builtin matchers\n\n| Matcher Name          | Description                                                                  |\n|-----------------------|------------------------------------------------------------------------------|\n| `BeBetween(min, max)` | Checks that all given values are between a minimum and maximum value         |\n| `BeEmpty()`           | Checks that all given values are empty                                       |\n| `BeGreaterThan(min)`  | Checks that all given values are greater than a minimum value                |\n| `BeLessThan(max)`     | Checks that all given values are less than a maximum value                   |\n| `BeNil()`             | Checks that all given values are nil                                         |\n| `EqualTo(expected)`   | Checks that all given values are equal to their corresponding expected value |\n| `Fail()`              | Checks that the last given value is a non-nil `error` instance               |\n| `Not()`               | Checks that the given matcher fails                                          |\n| `Say()`               | Checks that all given values match the given regular expression              |\n| `Succeed()`           | Checks that the last given value is either nil or not an `error` instance    |\n\n## Contributing\n\nPlease do :ok_hand: :muscle: !\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for more information :pray:\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farikkfir%2Fjustest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farikkfir%2Fjustest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farikkfir%2Fjustest/lists"}