DEV Community

loading...

Discussion on: My experience trying TDD for the first time in Go

Collapse
charly3pins profile image
charly3pins

TDD is good in order to provide just the minimum code that passes the test, so the test must be a reflect of the reality you're modeling in your code. Said that I try to use it as much as possible because as you said it obligates you to think in the edge cases while writing code first not and avoids you to refactor later when that happens. For the mocks I started using the same lib as you and also mockery, but nowadays I prefer to write my own mocks depending on each case and save me one import

Collapse
bethanyj28 profile image
Bethany Author

That's a really interesting way to think of it. Like not aiming for perfection but having it serve as a guide for what your code should satisfy.

Interesting about the mocks! Do you have an example of what that looks like? I agree saving imports are nice, but to me the mocking frameworks save so much code while being very robust (allowing you to provide expected inputs and direct the outputs). Though it's very possible that I haven't seen a good hand-written mock!