DEV Community

Discussion on: Demonstrating TDD (Test-driven development) in Go

Collapse
 
rpgrca profile image
rpgrca

I know some Go but I usually code in .NET core, Python and Javascript so have to say that I find Go's handling of DDT (data-driven testing) pretty poor if you need to simulate it with a for loop. Is there another way of doing it? The code looks dirty, you got a loop inside a test method when unit tests in general (that means, applicable even if you are not using TDD) shouldn't have any logic, they should be atomic, with a single set of data and a single set of asserts per execution, which means no conditions, and a for loop includes one.

Not sure if it's a limitation of Go testing framework or not, that's why I ask if there's another way of implementing DDT.

Regards,

Collapse
 
individualit profile image
Artur Neumann

I think the loop is the way to do it in go see github.com/golang/go/wiki/TableDri...

Basically what you are doing in to multiple test runs by calling t.Run()