{"id":15035434,"url":"https://github.com/rubrikinc/testwell","last_synced_at":"2025-05-15T05:31:29.920Z","repository":{"id":57496170,"uuid":"137117977","full_name":"rubrikinc/testwell","owner":"rubrikinc","description":"Small, intuitive, and type-safe assertion library for unit testing in Go","archived":false,"fork":false,"pushed_at":"2025-01-15T21:06:49.000Z","size":32,"stargazers_count":3,"open_issues_count":0,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-03T04:33:06.965Z","etag":null,"topics":["golang","testing"],"latest_commit_sha":null,"homepage":null,"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/rubrikinc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-12T19:26:09.000Z","updated_at":"2023-06-24T14:06:52.000Z","dependencies_parsed_at":"2024-06-19T05:34:49.893Z","dependency_job_id":null,"html_url":"https://github.com/rubrikinc/testwell","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubrikinc%2Ftestwell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubrikinc%2Ftestwell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubrikinc%2Ftestwell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubrikinc%2Ftestwell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rubrikinc","download_url":"https://codeload.github.com/rubrikinc/testwell/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254281962,"owners_count":22045061,"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":["golang","testing"],"created_at":"2024-09-24T20:28:41.275Z","updated_at":"2025-05-15T05:31:29.310Z","avatar_url":"https://github.com/rubrikinc.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# testwell\n\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/rubrikinc/testwell/blob/master/LICENSE)\n[![GoDoc](https://godoc.org/github.com/rubrikinc/testwell/assert?status.svg)](https://godoc.org/github.com/rubrikinc/testwell/assert)\n[![Go Report Card](https://goreportcard.com/badge/rubrikinc/testwell)](http://goreportcard.com/report/rubrikinc/testwell)\n\nA small set of type-safe convenient testing functions for Go.\n\nTwo identical packages (same API) are provided: `expect` and `assert`. Test\nfunctions from the `expect` package will perform the test, and on failure, will\nlog the result, and mark the test case as failed. Test functions from the\n`assert` package will do the same, and in addition, will fail the test case\nright away.\n\n## Example\n\n```go\nimport (\n    \"github.com/rubrikinc/testwell/expect\"\n    \"github.com/rubrikinc/testwell/assert\"\n    \"testing\"\n)\n\nfunc TestEx1(t *testing.T) {\n    assert.True(t, 42 == 42, \"this got to be true\")\n\n    expect.Equal(t, 42, 42)\n    expect.NotEqual(t, int8(42), int64(42), \"equality includes type!\")\n    expect.Contains(t, \"foo\", \"zingfoobar\", \"optional %s\", \"fmt msg\",)\n}\n```\n\n## Documentation\n\nUse `godoc`. For example:\n\n```shell\ngodoc -http :9090\n```\n\nThen navigate to\n[localhost](http://localhost:9090/pkg/github.com/rubrikinc/testwell/assert/).\nAlternatively, can view them online\n[here](https://godoc.org/github.com/rubrikinc/testwell/assert).\n\n## Code overview\n\n### Get involved\n\nWe are happy to receive bug reports, fixes, documentation enhancements, and\nother improvements.\n\nPlease report bugs via the\n[github issue tracker](https://github.com/rubrikinc/testwell/issues).\n\n#### Building and testing\n\nTo build and test locally, you need the following dependencies:\n - Go Language: [installation instructions](https://go.dev/doc/install)\n - `goimports`\n   ```shell\n   # Install\n   go install golang.org/x/tools/cmd/goimports@latest\n\n   # You may need to add `goimports` to `PATH` after installation.\n   export PATH=\"$HOME/go/bin:$PATH\"\n   ```\n\nBefore you can use `make`, be sure to have initialized the Go module.\n```shell\ngo mod init github.com/rubrikinc/testwell\n```\n\n### Testwell design rules\n\n - Naming is important, and good names should be used.\n - We must use type-checking when possible even though testing is a runtime\n   failure.\n - We must have consistent order of parameters. `*testing.T` first, left\n   value, right value, etc...\n - We must print out easy to read test failure message. Nobody has time to\n   waste deciphering them.\n\n### Code generation\n\nA small code generator can be found in `internal/codegen`. It takes a Go text\ntemplate file, and run it with a list of types. The unique template is\n`internal/assert.tmpl`.\n\nThe goal of the template is easily generate functions parameterized with\ndifferent type. Go doesn't offer generics as of Go 1.9.\n\n`internal/codegen/gen.sh` builds and run the code generator in a single pass.\n(We cannot use `go run` because it doesn't support multiple files package).\n\nThe packages `assert`, `expect` and `internal/tests` all have a `lib.go` file\nwith a `go generate` comment for running `internal/codegen/gen.sh`. This\ngenerates `assert.go` (`expect.go` for the package `expect`).\n\nThe generated code relies on finding the function\n`func failTest(t testing.T, tf fail.TestFailure) bool` in the same package.\nThis function is responsible for logging out the failed test, and taking the\nappropriate action (fail now, mark test as failed or log it for unit testing).\n\n## Motivation\n\nThis is our own version of set of helpers function for testing in Go. This\nmight requires some explanation as to why we needed to invest some effort into\nthat.\n\n### Testify is not the best choice\n\n[Testify](https://github.com/stretchr/testify) has become more or less the\nstandard for convenient test functions. However it has a few flaws:\n\n - In Go, no two different types can be compared (with the notable exception of\n   `nil`). Even something that looks trivial at first glance, comparing\n   `int8(42)` to `int32(42)` is not possible in Go. If you are wondering why,\n   look at the mess of automatic widening coercion rules in C/C++.\n \n   Testify however allows comparing of different types to make writing the code\n   more convenient. However, when the comparison fails due to mismatched types\n   (but not values!), Testify usually doesn't provide enough contextual\n   information on the type being compared, making it difficult to understand why\n   `42 is not equal to 42`. One could be an `int32` and the other a `string`.\n\n - Arguments to the different helpers functions are not always consistent.\n   Sometimes the expected value is first sometimes second.\n\n - Naming is poor. One example is the `Contains` function from Testify. Not\n   only does it takes its argument in a reversed order compared to most other\n   functions, it also has the variable `s` for the container and `contains` for\n   the element to search within the container. Another example is the package\n   `assert` which doesn't do assertion, but log failure and marks the test case\n   as failed.  Which is contrary to what most programmers are used to. While\n   the package `require` is doing failing assertion.\n\n - Go 1.9 improved the situations of test helper functions by adding a\n   mechanism to mark them explicitly. We take advantage of this in this\n   library.\n\n## Licensing\n\nThis library is MIT-licensed.\n\n## Copyright\n\nCopyright © 2022 ([Rubrik Inc.](https://www.rubrik.com))\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubrikinc%2Ftestwell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubrikinc%2Ftestwell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubrikinc%2Ftestwell/lists"}