|
|
7 лет назад | |
|---|---|---|
| .. | ||
| .gitignore | 7 лет назад | |
| .travis.yml | 7 лет назад | |
| LICENSE | 7 лет назад | |
| Makefile | 7 лет назад | |
| README.md | 7 лет назад | |
| assertions.go | 7 лет назад | |
| go.snippets | 7 лет назад | |
| goblin.go | 7 лет назад | |
| goblin_logo.jpg | 7 лет назад | |
| goblin_output.png | 7 лет назад | |
| mono_reporter.go | 7 лет назад | |
| reporting.go | 7 лет назад | |
| resolver.go | 7 лет назад | |
A Mocha like BDD testing framework written in Go that requires no additional dependencies. Requires no extensive documentation nor complicated steps to get it running.
Inspired by the flexibility and simplicity of Node BDD and frustrated by the rigorousness of Go way of testing, we wanted to bring a new tool to write self-describing and comprehensive code.
go testDescribe and It blocks as you wantBefore, BeforeEach, After and AfterEach for setup and teardown your testsDescribe and It blocksSince go test is not currently extensive, you will have to hook Goblin to it. You do that by
adding a single test method in your test file. All your goblin tests will be implemented inside this function.
package foobar
import (
"testing"
. "github.com/franela/goblin"
)
func Test(t *testing.T) {
g := Goblin(t)
g.Describe("Numbers", func() {
// Passing Test
g.It("Should add two numbers ", func() {
g.Assert(1+1).Equal(2)
})
// Failing Test
g.It("Should match equal numbers", func() {
g.Assert(2).Equal(4)
})
// Pending Test
g.It("Should substract two numbers")
// Excluded Test
g.XIt("Should add two numbers ", func() {
g.Assert(3+1).Equal(4)
})
})
}
Ouput will be something like:
Nice and easy, right?
Yes! Goblin will help you to test asynchronous things, like goroutines, etc. You just need to add a done parameter to the handler function of your It. This handler function should be called when your test passes.
...
g.Describe("Numbers", func() {
g.It("Should add two numbers asynchronously", func(done Done) {
go func() {
g.Assert(1+1).Equal(2)
done()
}()
})
})
...
Goblin will wait for the done call, a Fail call or any false assertion.
Gomega is a nice assertion framework. But it doesn't provide a nice way to hook it to testing frameworks. It should just panic instead of requiring a fail function. There is an issue about that here. While this is being discussed and hopefully fixed, the way to use Gomega with Goblin is:
package foobar
import (
"testing"
. "github.com/franela/goblin"
. "github.com/onsi/gomega"
)
func Test(t *testing.T) {
g := Goblin(t)
//special hook for gomega
RegisterFailHandler(func(m string, _ ...int) { g.Fail(m) })
g.Describe("lala", func() {
g.It("lslslslsls", func() {
Expect(1).To(Equal(10))
})
})
}
If -goblin.run=$REGES is supplied to the go test command then only tests that match the supplied regex will run
We do have a couple of issues pending. Feel free to contribute and send us PRs (with tests please :smile:).
Special thanks to Leandro Reox (Leitan) for the goblin logo.