Skip to content

Commit 5ba2235

Browse files
committed
doc: update readme.
1 parent dc197e0 commit 5ba2235

File tree

1 file changed

+80
-1
lines changed

1 file changed

+80
-1
lines changed

README.md

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,80 @@
1-
# go-assert
1+
# Assertion for Golang
2+
3+
![test](https://github.com/ghosind/go-assert/workflows/test/badge.svg)
4+
[![codecov](https://codecov.io/gh/ghosind/go-assert/branch/main/graph/badge.svg)](https://codecov.io/gh/ghosind/go-assert)
5+
![Version Badge](https://img.shields.io/github/v/release/ghosind/go-assert)
6+
![License Badge](https://img.shields.io/github/license/ghosind/go-assert)
7+
[![Go Reference](https://pkg.go.dev/badge/github.com/ghosind/go-assert.svg)](https://pkg.go.dev/github.com/ghosind/go-assert)
8+
9+
A collection of Golang assertion functions for verifying invariants.
10+
11+
## Installation
12+
13+
To install this library, just use `go get` command like the following line:
14+
15+
```bash
16+
go get -u github.com/ghosind/go-assert
17+
```
18+
19+
## Getting Started
20+
21+
This library provided assertion functions to verify the equality of values:
22+
23+
```go
24+
func TestExample(t *testing.T) {
25+
// assert equality
26+
assert.DeepEqual(t, actual, expect)
27+
28+
// assert inequality
29+
assert.NotDeepEqual(t, actual, expect)
30+
}
31+
```
32+
33+
It also provided assertion functions to verify a function will panic or not:
34+
35+
```go
36+
func TestPanic(t *testing.T) {
37+
// assert panic
38+
assert.Panic(t, func () {
39+
// do something
40+
41+
panic()
42+
})
43+
44+
// assert no panic
45+
assert.NotPanic(t, func () {
46+
// do something
47+
48+
// panic()
49+
})
50+
}
51+
```
52+
53+
Every assertion will not terminate the testing workflow. However, they'll return an error if the verification failed, and you can check the return value to get the verification result.
54+
55+
```go
56+
func TestExample(t *testing.T) {
57+
if err := assert.DeepEqual(t, actual, expect); err != nil {
58+
// terminate test
59+
t.Fail()
60+
}
61+
}
62+
```
63+
64+
If you need to assert many times, you can also create an `Assertion` instance:
65+
66+
```go
67+
func TestExample(t *testing.T) {
68+
assertion := assert.New(t)
69+
70+
// test equality
71+
assertion.DeepEqual(actual, expect)
72+
73+
// Test inequality
74+
assertion.NotDeepEqual(actual, expect)
75+
}
76+
```
77+
78+
## License
79+
80+
This project was published under the MIT license, you can see [LICENSE](./LICENSE) file to get more information.

0 commit comments

Comments
 (0)