Closed ghostsquad closed 6 years ago
The reason you are getting a panic is because gunit is designed to instantiate fresh instances of ExampleFixture
and it takes care of embedding the *testing.T
in the *gunit.Fixture
behind the scenes. Setting it manually before calling gunit.Run
is a no-op.
gunit was designed to work specifically with our own assertions library. We don't have any plans to add support for testify or any other testing libraries/frameworks.
I'll rewrite your test example using the approved method:
package foo
import (
"testing"
"github.com/smartystreets/assertions/should"
"github.com/smartystreets/gunit"
)
func Test(t *testing.T) {
gunit.Run(new(ExampleFixture), t)
}
type ExampleFixture struct {
*gunit.Fixture
}
func (this *ExampleFixture) TestFoo() {
// option 1, use the Assert function, which allows a custom message in case of failure:
this.Assert(123 == 123, "they should be equal")
// option 2, use our assertions library and print your own message is case of failure:
if !this.So(123, should.Equal, 123) {
this.Println("They should be equal!")
}
}
Would that satisfy your needs?
Well I started using the smartystreets/assertions library, but I wanted to play with other assertion libraries. So, technically no this doesn't solve the problem. But you answered the question of why they aren't compatible. Thanks!
I'm not sure if this is a problem with Testify or this framework, so I'm starting here.
Expected Behavior
Test passes
Actual Behavior
Runtime Panic
Minimum Repro steps
import ( "testing" "github.com/smartystreets/gunit" "github.com/stretchr/testify/assert" )
func Test(t *testing.T) { f := new(ExampleFixture) f.t = t gunit.Run(f, t) }
type ExampleFixture struct { gunit.Fixture t testing.T }
func (this *ExampleFixture) TestFoo() { assert.Equal(this.t, 123, 123, "they should be equal") }
$ go test ./maps/foo/example_test.go --- FAIL: Test (0.00s) --- FAIL: Test/TestFoo (0.00s) test_case.go:67: Test definition:
FAIL FAIL command-line-arguments 0.010s