4 ms·
Wow when did they add that to TestComments? I really disagree though. The native testing framework is overly clunky and verbose. It also makes things harder to
by nvarsj 6y ago
Wow when did they add that to TestComments?
I really disagree though. The native testing framework is overly clunky and verbose. It also makes things harder to debug when they fail. Just look at the example it gives! You don't even know why the test failed, it combines 4 different tests in one line. Are you supposed to inspect the entire object that gets printed out to figure it out? How terrible.
- jrockway 6y agoYeah, it's a really bad example. I would just cmp.Diff, and if I only cared about 4 fields, I would delete the data from got.FieldIDontCareAbout before comparison. (You can also make cmp.Diff do this if you want to do it every time.) I think that an evolution of tests would be: assert.Equals(got.Bar, want.Bar) assert.Equals(got.Baz, want.Baz) then: if got.Bar != want.Bar || got.Baz != want.Baz { t.Fatalf("bar and baz:\n got: %v\n want: %v", got, want) } then: want := Thing{Bar: xxx, Baz: yyy} got.Quux = "" if diff := cmp.Diff(got, want); diff != "" { t.Fatal("bar and baz:\n%s", diff) } (cmp.Ignore and friends should also be considered for less misleading output, if you don't care about Quux) Basically, cmp.Diff should be your go-to testing framework. It's easy to use and the output is excellent.