smarty / gunit

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

Output of failed assertion in Setup/TearDown method lacks test name and originating file:line info #11

Closed mdwhatcott closed 6 years ago

mdwhatcott commented 6 years ago
func (this *MyFixture) TestSomething() {
    // ...
}

func (this *MyFixture) Teardown() {
    this.So(true, should.BeFalse)
}

Test Output:

        fixture.go:96: 
            Test:     .()
            (0):      /Users/mike/src/github.com/smartystreets/stuff/stuff.go:6
            Expected: false
            Actual:   true

Notice, there's no Test name (instead: .()) and there's only the file:line info for the exact line of the assertion, any indicator of the file:line of the current test is missing. Would it be possible to back-fill that information from within the deferred Teardown call?

Expected Test Output:

        fixture.go:96: 
            Test:     MyFixture.TestSomething()
            (1):      /Users/mike/src/github.com/smartystreets/stuff/stuff.go:6
                (0):      /Users/mike/src/github.com/smartystreets/stuff/stuff.go:1
            Expected: false
            Actual:   true
mdwhatcott commented 6 years ago

This will require some sort of AST scan to build up a map[fixture-name|test-name]file:line. We can get the *testing.T.Name() when any assertion fails and get to the file:line of the containing test.