Sunday, 22 October 2017

Mocking in Go

I was recently asked to help out on a project with the aim of recommending how to implement some additional event handling functionality. I had a look through the source code and suggested a change to an existing interface implementation, plus a few other bits and pieces; all pretty straightforward or so I thought. Later, one of the developers said to me that he'd rather not change that particular piece of code as it was a crucial piece of code and he didn't know what else might break if it were changed. And that's when the alarm bells started ringing, it was a deeply worrying statement.

One of the things I believe is that you should always have the confidence to take software apart and change, redevelop and fix any part of it you like. The thing that gives you this confidence are unit tests; if you screw up a change the tests will fail and you'll know that you've made a mistake and you can fix things. Unit tests also mean that, when you've moved on, other developers can also have the confidence to take your software apart.

Given this statement I had to find out what was going on, so I did a review of the software and uncovered the fact that there weren't many unit tests, in fact some areas didn't have any at all... but they did have a number of integration tests. Strange. What was going on?
Were they just poor programmers? Didn't they realise that you can write unit tests in Go? Were the developers so naive that they thought that they didn't need tests?