Git Product home page Git Product logo

goblin's Introduction

Build Status Goblin

A Mocha like BDD testing framework for Go

No extensive documentation nor complicated steps to get it running

Run tests as usual with go test

Colorful reports and beautiful syntax

Why Goblin?

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.

What do I get with it?

  • Preserve the exact same syntax and behaviour as Node's Mocha
  • Nest as many Describe and It blocks as you want
  • Use Before, BeforeEach, After and AfterEach for setup and teardown your tests
  • No need to remember confusing parameters in Describe and It blocks
  • Use a declarative and expressive language to write your tests
  • Plug different assertion libraries (Gomega supported so far)
  • Skip your tests the same way as you would do in Mocha
  • Automatic terminal support for colored outputs
  • Two line setup is all you need to get up running

How do I use it?

Since 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() {
        g.It("Should add two numbers ", func() {
            g.Assert(1+1).Equal(2)
        })
        g.It("Should match equal numbers", func() {
            g.Assert(2).Equal(4)
        })
        g.It("Should substract two numbers")
    })
}

Ouput will be something like:

Nice and easy, right?

Can I do asynchronous tests?

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.

How do I use it with Gomega?

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))
        })
    })
}

TODO:

We do have a couple of issues pending we'll be addressing soon. But feel free to contribute and send us PRs (with tests please ๐Ÿ˜„).

Contributions:

Special thanks to Leandro Reox (Leitan) for the goblin logo.

goblin's People

Contributors

marcosnils avatar xetorthio avatar

Watchers

lemonhall avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.