virtcontainers icon indicating copy to clipboard operation
virtcontainers copied to clipboard

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

Open jodh-intel opened this issue 8 years ago • 6 comments

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.

jodh-intel avatar Apr 10 '17 16:04 jodh-intel

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

dlespiau avatar Apr 10 '17 17:04 dlespiau

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?

jodh-intel avatar Apr 11 '17 11:04 jodh-intel

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

dlespiau avatar Apr 11 '17 12:04 dlespiau

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.

jodh-intel avatar Apr 11 '17 12:04 jodh-intel

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 ?

egernst avatar Feb 15 '18 16:02 egernst

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

jodh-intel avatar Feb 19 '18 16:02 jodh-intel