Open aaslamin opened 5 years ago
@aaslamin - The GoConvey test DSL and table-driven tests are quite different in their approach. I doubt I ever had hopes to combine or synthesize them. Could you post an example of what you are trying to accomplish?
Here is one @mdwhatcott
In the example below, I want to run the failing test case test case 3
in isolation so I can debug it. But, I cannot.
https://play.golang.org/p/K8X8xvkQdl2
package main
import (
"fmt"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func SillyFunc(fail bool) error {
if fail {
return fmt.Errorf("error: i failed because i was told to do so")
}
return nil
}
func TestSillyFunc(t *testing.T) {
testCases := map[string]struct {
input bool
shouldError bool
}{
"test case 1": {
input: false,
shouldError: false,
},
"test case 2": {
input: false,
shouldError: false,
},
// notice how this test fails - I want to run this test case in isolation so I can debug it!
"test case 3": {
input: true,
shouldError: false,
},
"test case 4": {
input: false,
shouldError: false,
},
"test case 5": {
input: false,
shouldError: false,
},
}
Convey("TestSilly", t, func() {
for description, test := range testCases {
Convey(description, func() {
So(SillyFunc(test.input) != nil, ShouldEqual, test.shouldError)
})
}
})
}
Output of go test -v
go test -v -count=1
=== RUN TestSillyFunc
TestSilly
test case 1 ✔
test case 2 ✔
test case 3 ✘
test case 4 ✔
test case 5 ✔
Desired goal
Be able to use the standard go CLI to run the failing test case (test case 3
) in isolation via passing a pattern to the run
flag as per documented in https://blog.golang.org/subtests
Other:
Also note that the test output without passing -v
argument does not print any information regarding the test case that failed. In CI, you would have to pass the -v
flag all the time which would cause a lot of noise as it will still print things even if a test suite passes.
Using the standard library, one is able to filter/run (a) specific (sub) test(s) by passing a pattern to the
go test
command - https://blog.golang.org/subtestse.g.
go test -run=myregexpattern
Adopting a table driven test style with Convey (example), when a test fails, one cannot run that specific test in isolation without commenting out test cases you are not interested in. This is not practical if your test table is huge. Ideally, I shouldn't need to touch the structure of my tests to run them in isolation.
I saw https://godoc.org/github.com/smartystreets/goconvey/convey#FocusConvey, but it's not useful for a table driven style.
Thoughts?