Testing in Go: philosophy and tools
Testing in Go: philosophy and tools
Posted May 26, 2020 22:55 UTC (Tue) by phlogistonjohn (subscriber, #81085)Parent article: Testing in Go: philosophy and tools
On a different note, I didn't quite see the rationale for Cleanup, given that Go has defer. The issue that ended up getting the feature added seems to be the clearest explanation of the why behind Cleanup: https://github.com/golang/go/issues/32111
Personally, I don't see it as all that compelling but not bad or anything. :-)
Posted May 27, 2020 6:03 UTC (Wed)
by kokkoro (guest, #139153)
[Link]
Defer doesn't work properly with parallel tests. If you do:
Testing in Go: philosophy and tools
then f.Close() will be called immediately, concurrent to all of the parallel subtests.
https://github.com/golang/go/issues/17791
func TestFoo(t *testing.T) {
f := NewFoo()
defer f.Close()
for _, c := testCases {
c := c
t.Run(c.name, func(t *testing.T) {
t.Parallel()
c.func(t, f)
})
}