Summary from the July presentation: There are a couple of interesting testing libraries in go. "testing" comes with the standard library, and gives only very basic support for asserting facts.
Of the other libraries, I recommend looking at "testify/assert", "zen", and "gocheck". testify/assert is used in conjunction with testing to which it adds a lot of useful assertions, but doesn't change the basics of how a test is written. Zen implements the best version of BDD style testing I have seen in go. Essentially, you write one test into which you embed describes, its, and expects. Like testify/assert "gocheck" comes with many matchers out of the box. Gocheck requires creating a suite struct and uses a non-standard way of running the test methods. Its most useful feature to me are setup and teardown methods to allow tests in a suite to share common code. The shared state can lead to problems with concurrent code.
As far as the other libraries go, check them out to see the different styles. Beware of go-spec: The version tested here, never fails assertions!
So, summary of the summary: if you are just trying to test stuff and need assertions, go with testify/assert. If you want to see and play with BDD for go, use zen.
Slides from my presentation at Denver Gopher's 7/25/2013
Comparison of go lang testing libraries
-
testing: http://golang.org/pkg/testing/
Last Activity: - -
GoConvey: https://github.com/smartystreets/goconvey/
Last Activity: 3 hours ago 11/16/2013 -
testify: https://github.com/stretchr/testify/
Last Activity: 7 days ago on 7/24/2013 -
gocheck: http://labix.org/gocheck
Last Activity: 30 days ago on 7/24/2013 -
prettytest: https://github.com/remogatto/prettytest
Last Activity: 90 days ago on 7/24/2013 -
go-spec: https://github.com/bmatsuo/go-spec
Last Activity: 700 days ago on 7/24/2013 -
gospec: https://github.com/orfjackal/gospec
Last Activity: 350 days ago on 7/24/2013 -
mao: https://github.com/azer/mao
Last Activity: 17 days ago on 7/9/2013 -
zen: https://github.com/pranavraja/zen
Last Activity: 14 days ago on 7/13/2013 -
Ginkgo: https://github.com/onsi/ginkgo Gomega: https://github.com/onsi/gomega Last Activity: an hour ago on 1/18/2014
- GoConvey
- submit a pull request!
Name | testing | Ginkgo | GoConvey | testify | gocheck | prettytest | go-spec | gospec | mao/zen |
---|---|---|---|---|---|---|---|---|---|
License | BSD | MIT | MIT | MIT | BSD | MIT | BSD | Apache | MIT/Apache |
Assertions | Gomega | uses gocheck | |||||||
Style | make your own | spec | spec | assert | spec | spec | spec | spec | spec |
Equal | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
IsSame | ✓ | ✓ | ✓ | ||||||
DeepEqual | ✓ | ✓ | ✓ | ✓ | |||||
True | ✓ | ✓ | ✓ | ✓ | |||||
False | ✓ | ✓ | ✓ | ✓ | |||||
Nil | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
Empty | ✓ | ✓ | ✓ | ||||||
Error | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |||
Implements | ✓ | ✓ | ✓ | ||||||
IsType | ✓ | ✓ | ✓ | ✓ | ✓ | ||||
StringContains | ✓ | ✓ | ✓ | ||||||
StringMatches | ✓ | ✓ | ✓ | ||||||
Collection | ✓ | ✓ | ✓ | ||||||
Panics | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |||
HasLen | ✓ | ✓ | ✓ | ||||||
Matches | ✓ | ✓ | ✓ | ||||||
Satisfy | ✓ | ✓ | |||||||
Within | ✓ |
*CollectionContains allows checks for All, Any, Exactly, InOrder, and InPartialOrder
The code to be tested is taken from the cloudfoundry loggregator project. Specifically, we are testing a piece that receives data on a channel and sends it off via UPD. We will be testing that the code sends data, but that it does not send any empty data it might receive.
All the tests are in packages relating to their name within the gotestit package.