The Startup
Published in

The Startup

Unit Testing CLI Programs in Go

Photo by John Schnobrich on Unsplash

It’s a common scenario — for me at least — to be building a CLI tool (main package) that has CLI options (flags package) that I want to add unit tests to.

Here’s a simple example of a CLI tool that adds or multiplies some input numbers:




Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +756K followers.

Recommended from Medium

Cloning,Branching and creating Pull Requests using Github

Project Budgets: Tips for Estimating & Cost Tracking

What i’ve learnt so far as a software engineer

Create container image that’s has python3 and keras or numpy installed using Dockerfile.

Reduce Cost and Increase Productivity with Value Added IT Services from buzinessware — {link} -

Quantum Programming: Introduction to the Z gate with code

Python program to find the distance between two points(xc,yc) and (xp,yp)

Review of Machine Learning with Python-From Linear Models to Deep Learning on Edx

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
Elliot Chance

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. 🤓

More from Medium

Echo 101: Manage config files in Cloud Native way

Mocking HTTP Call in Golang a Better Way

Photo by @jim_reardan on Unsplash

Unit Testing & Debugging Setup For Golang with VS Code

Go Context for a layman