Hacker News new | ask | show | jobs
by trung_pham 5008 days ago
It's very hard to do Test Driven Development in Go because there is no mocking library that can help with stubbing constructor or static method.

I feel that people who jumped ship from dynamic language such as Ruby or Python to Go have no idea what they are giving up. Maybe they never practiced TDD to begin with.

Heck, even Java is more friendly with TDD by using Powermock or JMockit library.

1 comments

It's very hard to do Test Driven Development in Go because there is no mocking library that can help with stubbing constructor or static method.

Well, you'll be happy to learn that Go doesn't have constructors or static methods, then. :)

What Go does have is a standard unit testing framework which is quite nice: http://golang.org/pkg/testing/

"Mocks" in general are a cumbersome and somewhat lame attempt to deal with the many limitations of inheritance-based designs in languages such as Java. In Go, there's no need to create a Mock, because you can easily create a wrapper object for whatever object you want to test using Go's anonymous member syntax. Then you simply override whatever methods you want to on the wrapper object, and let the others get passed through.