smarty / gunit

xUnit-style test fixture adapter for go test
Other
120 stars 11 forks source link

No more `go generate`! #6

Closed mdwhatcott closed 8 years ago

mdwhatcott commented 8 years ago

Interestingly, the advent of subtests in the testing package makes it possible to implement a reflection-based test runner that achieves proper partitioning of test cases with absolutely no breaking changes to the existing API. This runner makes the gunit command unnecessary (but it will still hang around for a while) and so we no longer need to put the go generate compiler directive in our code or run go generate for any reason related to testing.

Here's an example of how to use it:

package stuff

import (
    "testing"

    "github.com/smartystreets/assertions/should"
    "github.com/smartystreets/gunit"
)

func TestStuff(t *testing.T) { // This function is the new boilerplate. Not too bad.
    gunit.Run(new(StuffFixture), t)
}

type StuffFixture struct {
    *gunit.Fixture
}

...

Just run go test -v in the samples and you'll see it in action.

The only downside right now is that the Go Intellij Plugin doesn't yet support displaying subtests in the test report window. So, this PR is, for all intents and purposes, blocked by that issue (which may be blocked on go test getting a -json flag).

mdwhatcott commented 8 years ago

gunit: no more go generate!