[ANN] Ginkgo & Gomega: BDD Style Testing for Golang

402 views
Skip to first unread message

Onsi Fakhouri

unread,
Dec 6, 2013, 9:23:44 AM12/6/13
to golan...@googlegroups.com
Hey all,

I've been meaning to announce this to the golang-nuts list for a while :)

Ginkgo is a mature feature-rich BDD-style testing framework for Go with a laundry list of features:

Gomega is Ginkgo's preferred matcher/assertion library:

Here's a blog post announcement from a couple of months ago:

And there's plenty of documentation of both the /doc and /pkg variety:
...and godoc of course!

Enjoy!

Chris Maddox

unread,
Dec 6, 2013, 6:36:19 PM12/6/13
to golan...@googlegroups.com
Hey Onsi,

Firstly, thank you for you hard work on these projects. I've been using both for about a week and they are a great addition.

To mimic stubs/mocks for external systems, would you suggest using dependency injection? Specifically, when building an API client, what's the best way to test the calls without hitting the service itself?

Thanks!
Chris

AllenDang

unread,
Dec 6, 2013, 9:00:11 PM12/6/13
to golan...@googlegroups.com
Thanks! It looks great! Can't wait to write some tests. :)

Onsi Fakhouri

unread,
Dec 6, 2013, 11:51:18 PM12/6/13
to golan...@googlegroups.com
Thanks Chris!

Regarding stubs/mocks: exactly -- I use interfaces for all my dependencies and then inject fakes under test.  For faking out (http) API end points you can look into using the built-in http://golang.org/pkg/net/http/httptest/.  This allows you (basically) to fake out the server end of things.  I actually think there's a better approach to this, though, but it requires a bit more infrastructure and some non-trivial fakes.  Rather than fake out the server I find it much more flexible to fake out the client.  This allows me to grab a network request under test *after* the code has made the request and then make assertions on it and then exercise it under different conditions (what happens when it 200s?  what happens when it 404s? etc...)  There's a (very complicated... sorry!) example of this here: https://github.com/cloudfoundry/hm9000/blob/master/desiredstatefetcher/desired_state_fetcher_test.go

Best,

Onsi
Reply all
Reply to author
Forward
0 new messages