DEVELOPER ESSENTIALS

Unit Testing in Python

Code Confidently and Break Stuff on Purpose

SJ Porter
The Startup
Published in
8 min readJul 8, 2019

--

Introduction

For anyone unfamiliar with the concept, unit testing is the practice of writing a series of tests (or “assertions”) regarding the behavior of your code to ensure that everything works as expected. Unit tests can be run at any point, over and over again, to reinforce your confidence in what you’ve written and allow you to understand (and often redefine) how your code handles various scenarios. By comprehensively testing both the “happy path” and “edge cases”, you can protect your code against breaking changes in the future.

Why unit testing is essential

Without unit tests, it may be very intimidating for you to make a major change or addition to your project later on down the road without introducing other problems. […] With unit tests in place, you can confidently add functionality to your project later on and ensure that all of the assumptions you previously had about how your code behaves still hold true.

Personally, I heard about the basic concepts of unit testing well before I used them in the Python language. I would venture a guess that many others have had a similar experience. Despite this, I firmly believe that unit testing is the single most important programming concept I’ve ever learned. I’ve grown immensely as a developer since I started writing unit tests, and it has encouraged me to…

--

--

SJ Porter
The Startup

Data/cloud engineer, musician, and gamer. Editor for Low Code for Advanced Data Science, writer for TDS and The Startup.