Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/goenning/expect
An opinionated and minimalist assert module for Go
https://github.com/goenning/expect
Last synced: 13 days ago
JSON representation
An opinionated and minimalist assert module for Go
- Host: GitHub
- URL: https://github.com/goenning/expect
- Owner: goenning
- License: mit
- Created: 2021-02-26T20:40:58.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-02-26T22:24:28.000Z (almost 4 years ago)
- Last Synced: 2024-11-02T19:41:38.296Z (2 months ago)
- Language: Go
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# github.com/goenning/expect
An opinionated and minimalist assert module for Go
📦 Zero Dependencies
## What it does
Writing assertions for unit test using Go standard can be quite cumbersome and repetitive. `expect` is a tiny library that simplifies and adds more clarify to assertions.
Before:
```go
if err != nil {
t.Fatalf("Err is not nil")
}
if number != 4 {
t.Fatalf("Number is not 4")
}
```After:
```go
Expect(err).IsNil()
Expect(result).Equals(4)
```## How to use
```go
import (
. "github.com/goenning/expect"
)func TestCanAddNumbers(t *testing.T) {
RegisterT(t)result, err := DoSomething()
Expect(err).IsNil()
Expect(result).Equals(4)
}
```All supported assertion operations:
- Equals(expected)
- NotEquals(other)
- ContainsString(substr)
- IsTrue()
- IsFalse()
- IsEmpty()
- IsNotEmpty()
- IsNotNil()
- IsNil()
- HasLen(length)
- Panics()
- EventuallyEquals(expected)
- WithinTime(time, duration)