Skip to content
This repository has been archived by the owner on Apr 3, 2018. It is now read-only.

Switch tests to use a testing framework that provides fixtures (test setup / tear down functions). #187

Open
jodh-intel opened this issue Apr 10, 2017 · 6 comments

Comments

@jodh-intel
Copy link
Collaborator

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.

@dlespiau
Copy link

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

@jodh-intel jodh-intel changed the title Switch tests to use gocheck for fixtures such as SetUpTest() Switch tests to use a testing framework that provides fixtures (test setup / tear down functions). Apr 11, 2017
@jodh-intel
Copy link
Collaborator Author

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?

@dlespiau
Copy link

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

@jodh-intel
Copy link
Collaborator Author

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.

@egernst
Copy link
Collaborator

egernst commented Feb 15, 2018

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 ?

@jodh-intel
Copy link
Collaborator Author

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...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants