gotests icon indicating copy to clipboard operation
gotests copied to clipboard

Potencial improvements to default tests template

Open matrixik opened this issue 5 years ago • 3 comments

I'm not sure if this will be interesting for this project but Dave Cheney gave nice presentation about writing tests for Go code with some improvements over default template from gotests: https://dave.cheney.net/paste/gopherchina-2019-testing-talk.pdf

Like having name in map[string]struct instead of []struct or using https://github.com/google/go-cmp Diff for better displaying what differ between outputs (instead of %v).

matrixik avatar May 06 '19 08:05 matrixik

@matrixik added PR for cmp.Equal and cmp.Diff in generated tests

for changing from

struct {
   name string
 ...
}

to

  map[string]struct{
 ...
}

I think it's better to create different issue for changing struct slice to map struct

mekegi avatar May 13 '19 15:05 mekegi

I think if we have a complex scenario like if we have in order dependency, the map randomly maybe cause result will be unknown. and if need that map style, generated then manually modify also is easy.

frenzywang avatar May 14 '19 03:05 frenzywang

@matrixik I feel the same. @davecheney wrote a great article about PROs to stick with maps in table-driven tests. Now, I'm manually changing the generated output from the tool to use map[string]struct.

skovtunenko avatar Apr 21 '20 17:04 skovtunenko