Tests for GoBlog

Recently I’ve been investing more time in refactoring and creating unit and integration tests for GoBlog. After all, I don’t want to just make sure my blog is working properly through trial and error, I want to be able to prove that with automated tests.

The current state is 6% test coverage.

Creating automated tests is actually (admittedly) more fun than I thought it would be. I keep discovering little bugs or places where I can improve the code further. Also, sometimes I have to think of ways to test something in the first place.

For example, how do I test HTTP calls to external APIs? The solution I found for this today is to mock an HTTP client in the test, so I can intercept and examine the requests.

And I’m getting more and more familiar with Go itself, but also with best practices. Maybe this will help me in the long run with my professional programming and an eventual career.

Interactions & Comments