Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/janstuemmel/easy-assert
simple go assertion library
https://github.com/janstuemmel/easy-assert
assert go golang
Last synced: 25 days ago
JSON representation
simple go assertion library
- Host: GitHub
- URL: https://github.com/janstuemmel/easy-assert
- Owner: janstuemmel
- License: mit
- Created: 2018-11-30T17:16:35.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-01T20:48:46.000Z (about 6 years ago)
- Last Synced: 2024-11-07T01:13:46.346Z (2 months ago)
- Topics: assert, go, golang
- Language: Go
- Size: 2.93 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# easy-assert [![Build Status](https://travis-ci.org/janstuemmel/easy-assert.svg?branch=master)](https://travis-ci.org/janstuemmel/easy-assert) [![Godoc](https://godoc.org/github.com/janstuemmel/easy-assert?status.svg)](http://godoc.org/github.com/janstuemmel/easy-assert)
A simple go assertion library.
You don't need this library, instead just copy following lines into your test file:
```go
func assert(t *testing.T, want interface{}, have interface{}) {// mark as test helper
t.Helper()// throw error
if want != have {
t.Errorf("Assertion failed for %s\n\twant:\t%+v\n\thave:\t%+v", t.Name(), want, have)
}
}
```## Usage
```go
package foo_testimport (
"testing"
"errors""github.com/janstuemmel/easy-assert"
)func TestFoo(t *testing.T) {
assert.Equal(t, 1, 1)
assert.Equal(t, 1, 2)// test thrown error
err := errors.New("foo")
assert.Equal(t, false, nil == err)// alternative
a := assert.New(t)
a.Equal(1, 1)
a.Equal(1, 2)
}
```