Replies: 1 comment
-
Hey Sorry for the late reply, I don't seem to get notifications on discussions. There's a few trade-offs to consider here. You could comfortably argue your top version is a little simpler to read but it's not as ergonomic in terms of running tests. If you wish to run an individual test, with table tests you can. With your approach you cannot. I'm happy with the table version because for all practical uses, I don't read the for-loop bit, I just expect the table to "describe the truth". |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey,
first off awesome work with the guide to learn go by using TDD. I love it ❤️
I wanted to suggest an alternative approach to table driven tests, which in my opinion is more readable and less clutter in the code. This refers to the Structs, methods & interfaces chapter.
At the end you introduce table driven testing and suggest to use a
name
variable in the struct to make the test more readable. I want to suggest the following alternative:This can of course be tranfered to any other use-case where you would use table driven testing. I think it is a lot more readable and cleaner compared to the original:
What do you think about this approach? Maybe worth mentioning in the docs?
Beta Was this translation helpful? Give feedback.
All reactions