Testing Tips for Intermediate Gophers: Coverage

This article will cover how to get visibility of your test coverage in Go. If you’re not comfortable with the basics of testing in Go, please checkout my earlier article aimed at beginners. Test coverage Test coverage gives you a high-level overview you how much of your production code was invoked in your tests (e.g. as a percentage), but it can also give you a lower-level view of exactly which lines are invoked or missed.

Function Types in Go

A while ago, I saw a question in a Go developer Slack channel that went something like this (translated): When would you want to define a function type like type MyFunc func(msg string) error? Do you have any examples? I replied with a http.HandlerFunc example (more on that below), but there were many developers smarter than me in that Slack channel, and I ended up learning a lot from the other answers to this question.

mokku -- How I built a Go Mocking framework in 5 days

This past week I’ve had the privilege of having a Hack Week where I work, where we can work on whatever we wanted. I ended up building Mokku – a mocking framework for Go that gets out of your way. Key features Invisible: No hard (import) or soft (//go:generate) dependencies to add to your codebase. Unintrusive: Can be included in any developer’s workflow. Doesn’t dictate or enforce how you use it after it’s written.

Testing Tips for Beginner Gophers

Let’s have a go at writing tests in Go. Puns aside, testing in Go is baked into the language. Assuming you’re comfortable with the Go basics, let’s get started with writing tests. First of all, the way you run all tests in the current package is: $ go test However, unless you’ve got tests in your project nothing is going to execute. Go tests have to follow these three rules:

jsonassert -- A test utility for comparing and verifying JSON

Today I released v1.0.0 of a Go package called jsonassert. It is my first self-motivated open source contribution that I think has a chance of being useful to someone other than just myself. Okay, that’s not quite true but it’s the first one I’ve written in Go. I realised the need for this package when attempting to increase the test confidence of a relatively untested package that sends JSON to a server.

Feature-oriented package structures and the default access modifier

In Java we have 4 access modifiers that can be applied to methods and fields of a class. In descending order of visibility, they are: public String publicModifier = "Anyone can access me"; protected String protectedModifier = "Only accessible to classes in the same package as me, and my subclasses"; String defaultModifier = "Only accessible to classes in the same package as me"; private String privateModifier = "Only accessible within this class"; This article is a love letter to the third in this list of modifiers, the one-who-shall-not-be-named.

Spring Dependency Injection Patterns -- The good, the bad, and the ugly

Spring developers will be familiar with its powerful Dependency Injection API. It allows you to declare @Beans that Spring then instantiates and manages. Any dependencies between these beans is then resolved by Spring and injected automagically. Three Annotation-based Injection Patterns There are three ways Spring lets you declare the dependencies of your class using annotations: Field injection (The bad) import org.springframework.beans.factory.annotation.Autowired; public class MyBean { @Autowired private AnotherBean anotherBean; //Business logic.

10 Basic Shell Commands Every Beginner Should Know

If you aspire to be a developer, sys-admin, or some other profession that relies on computers outside of word documents and excel spreadsheets then you ought to be comfortable with a command line. Software and IT professionals love their command-lines as it is much more powerful than any GUI could ever be. This article aims to get you started from no prior knowledge. If this is completely new material for you, I recommend that you keep a Finder/Windows Explorer/etc.

My Shiniest Vim Gems

Vim is highly customisable, and I recommend everyone tailor their config according to their own preferences. That being said, here are some bits I think people may want to steal from my .vimrc. I tried to avoid the more common options you’d find in similar articles written by others, such as enabling line numbers, tpope’s surround plugin, or sane backspacing, and focus on the lesser-known tricks and settings. General settings Highlight the current column Immediately find exactly where your cursor is, using set cursorcolumn.

Modern Approaches to Dealing with Legacy Code (x-post)

I wrote an article on how to manage your legacy systems using modern tools and techniques on my work blog. Please check it out.