ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - franela/goblin: Minimal and Beautiful Go testing framework
Minimal and Beautiful Go testing framework. Contribute to franela/goblin development by creating an account on GitHub.
Visit Site

GitHub - franela/goblin: Minimal and Beautiful Go testing framework

GitHub - franela/goblin: Minimal and Beautiful Go testing framework

Goblin

Build Status Go Reportcard GoDoc License Release

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.

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?

  • Run tests as usual with go test
  • Colorful reports and beautiful syntax
  • 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() {
        // 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?

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"
    goblin "github.com/franela/goblin"
    . "github.com/onsi/gomega"
)

func Test(t *testing.T) {
    g := goblin.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))
        })
    })
}

FAQ

How do I run specific tests?

If -goblin.run=$REGES is supplied to the go test command then only tests that match the supplied regex will run

Contributing

We do have a couple of issues pending. Feel free to contribute and send us PRs (with tests please :smile:).

Special Thanks

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

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory