Switch tests to use a testing framework that provides fixtures (test setup / tear down functions).
The tests are currently using the testing package, but http://labix.org/gocheck is much more powerful (and compatible with testing). Crucially the latter offers test fixtures like SetUpTest() and TearDownTest() to simplify the test code.
Such fixtures will be useful for #163.
What about using go sub-tests? https://blog.golang.org/subtests (search for "Setup and Tear-down")
As for the more friendly asserts, it seems the consensus is https://github.com/stretchr/testify/assert (look at the star numbers!)
A quick look suggests that subtests probably aren't ideal for us since getting that package to provide us with the behaviour we want would require a lot of rework (unless I've misunderstood what that package provides?)
gocheck simply requires the test prototypes to be changed and the single SetUpTest() and TearDownTest() to be defined.
testify looks interesting and does seem to offer the fixtures we need. Plus, as you say, it looks very popular which counts for something. I'd vote for testify or gocheck, but @sameo - what is your preference?
Sub-tests aren't a package, just a new method Run() on the t *testing.T object. One can call a Setup()/TearDown() function around a multitude of t.Run(): subtests sharing the same setup/teardown code.
func TestFoo(t *testing.T) {
Setup(t)
t.Run("A=1", func(t *testing.T) { ... }) // could be the name of a function defined elsewhere instead of an anonymous one
t.Run("A=2", func(t *testing.T) { ... })
t.Run("B=1", func(t *testing.T) { ... })
Teardown(t)
}
Yeah, I saw that example, but I want a per test setup / teardown function: I explicitly don't want to have to add 2 calls per existing test function for that.
seems at the very least this is implicitly below ZBB line :).
Is this something we still want to pursue and should keep in our backlog, @jodh-intel ?
I think it would be useful, but we've survived this long without it. Feel free to close so we can resurrect at a later time if needed...