Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/benmills/quiz
go testing library
https://github.com/benmills/quiz
Last synced: about 1 month ago
JSON representation
go testing library
- Host: GitHub
- URL: https://github.com/benmills/quiz
- Owner: benmills
- Created: 2013-06-02T07:12:10.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-09-19T15:39:42.000Z (about 11 years ago)
- Last Synced: 2024-04-17T02:56:29.293Z (7 months ago)
- Language: Go
- Size: 146 KB
- Stars: 2
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.mkd
Awesome Lists containing this project
README
# Quiz [![Build Status](https://travis-ci.org/benmills/quiz.png?branch=master)](https://travis-ci.org/benmills/quiz)
A very simple go testing library.
```go
func TestSimple(t *testing.T) {
test := quiz.Test(t)test.Expect(1 == 2).To.BeFalse()
test.Expect("my tests").ToNot.Contain("verbosity")
}
```## Usage
To install quiz all you need to do is `go get github.com/benmills/quiz`. Once you have it installed make sure to import it in the test files you plan on using quiz in.
To use quiz in a test case you need to wrap the `*testing.T` argument that is normally provided for test cases in a `quiz.Test`. This enhances the normal `testing.T` instance with more functionality.
```go
func TestFoo(t *testing.T) {
test := quiz.Test(t)
}
```Once we have `quiz.Test` we can make different kinds of assertions. Before we make an assertion we can decide if it will succeed or fail by using `To` or `ToNot`.
For example if we expect `foo` to be true we could write:
```go
test.Expect(foo).To.BeTrue()
```Or we could expect `foo` to not be true:
```go
test.Expect(foo).ToNot.BeTrue()
````To` and `ToNot` can be used with a number of matchers provided by quiz which will be covered next.
## Matchers
* `Equal(interface{})`
* `BeTrue()`
* `BeFalse()`
* `BeGreaterThan(int)`
* `BeLessThan(int)`
* `Contain(interface{})`#### Contain
Contain should be able to check if any type holds a value, such as slices, maps, or other stucts. The way it does this is by forcing both given values into strings using `fmt.Sprint`. As long as the given values print contained values correctly when passed into `fmt.Sprint` we can assert on them using `Contain`. Here are a few examples:
```go
test.Expect([]string{"foo", "bar"}).To.Contain("foo")
test.Expect(map[string]string{"age":"25"}).To.Contain("age")
```