https://github.com/gogunit/gunit
Go Unit testing assertions
https://github.com/gogunit/gunit
go golang testing
Last synced: 4 months ago
JSON representation
Go Unit testing assertions
- Host: GitHub
- URL: https://github.com/gogunit/gunit
- Owner: gogunit
- License: bsd-3-clause
- Created: 2023-02-25T19:51:03.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-02-07T19:25:25.000Z (over 1 year ago)
- Last Synced: 2026-02-10T21:44:41.893Z (5 months ago)
- Topics: go, golang, testing
- Language: Go
- Homepage:
- Size: 46.9 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gunit
[](https://github.com/gogunit/gunit/actions/workflows/go.yml)
[](https://github.com/gogunit/gunit/actions/workflows/codeql.yml)

[](https://goreportcard.com/report/github.com/gogunit/gunit)
[](https://godoc.org/github.com/gogunit/gunit/)
gounit is test assertions library for Go. It was developed to address the shortcoming of many assertion frameworks that employ assertion of types at runtime rather than compile time.
## Examples
```go
// direct assertion style
func Test_nine_plus_two_is_greater_than_ten(t *testing.T) {
actual := 9 + 2
expected := 10
gunit.Number(t, actual).GreaterThan(expected)
}
// wrap testing.T struct
func Test_nine_plus_two_is_greater_than_ten(t *testing.T) {
assert := gunit.New(t)
actual := 9 + 2
expected := 10
assert.Int(actual).GreaterThan(expected)
}
```
## Hammy Examples
```go
package adder
import (
"testing"
a "github.com/gogunit/gunit/hammy"
)
func Test_add_returns_expected_sum(t *testing.T) {
assert := a.New(t)
actual := Add(2, 3)
assert.Is(a.Number(actual).EqualTo(5))
}
```
```go
package service
import (
"errors"
"fmt"
"testing"
a "github.com/gogunit/gunit/hammy"
)
var errTimeout = errors.New("timeout")
func Test_run_wraps_timeout_error(t *testing.T) {
assert := a.New(t)
err := fmt.Errorf("request failed: %w", errTimeout)
assert.Is(a.ErrorIs(err, errTimeout))
}
```