Image for post
Image for post
Photo by Nick Fewings on Unsplash

I’m a big fan of TDD. BDD has always been a bit elusive to me in the sense that I wish I could use it more often. However, I always seem to end up struggling to express the same nuances through BDD that come effortlessly through a standard test case.

Truth be told, I have’t touched BDD in a while. However, this question has been bouncing around my head lately:

Why is it often so difficult to express simple systems through BDD?

Code based tests are really good at describing how we complete a task. BDD is really good at describing what a task is trying to achieve. …


Image for post
Image for post
Photo by DDP on Unsplash

Go’s error handling is very explicit. It can also be very verbose compared to other languages. I want to talk about how we can minimize the need for explicit error handling by separating what are expected and unexpected errors.

An expected error is generally something you can test/check/verify ahead of time or that would not have a detrimental effect on the system. Some examples of expected errors are:

  1. Validating an email address from an input.
  2. Verifying that a user has access to a certain part of the system.
  3. Retry on a known flaky or slow API endpoint.

Expected errors should always return an error. This lets the caller decide what to do in this case. It may want to bubble the error up, or it may choose to bail out of the current operation. …


Image for post
Image for post
Photo by Javier Allegue Barros on Unsplash

Go does not have any concept of enums like some other languages. There are arguments for and against this approach which I won’t go into here. However, there are times when you want to check that switch statements contain all enum values. Especially if you intend to add new enum values in the future and want to catch existing code that now needs to be updated accordingly.

For this, I developed a tool called switch-check. It’s a zero dependency, zero configuration CLI tool for doing just that. You can try it right now with:

go get -u github.com/elliotchance/switch-check
switch-check

Or, here is a quick…

About

Elliot Chance

I’m a data nerd and TDD enthusiast originally from Sydney. Currently working for Uber in New York. My thoughts here are my own. 🤓 elliotchance@gmail.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store