How to automate your tests: 3 methods

Mark McWiggins
2 min readApr 8, 2023

Automated testing is a method for running a suite of tests on code after every time a developer pushes a change to the repository.

How to do this?

There are at least three ways I’m familiar with:

Google Cloud Build … easiest to set up and works well:

Google cloud build trigger

Github workflows … well documented but doesn’t exist in enterprise Git systems

Github workflow ui

Git hooks .. the oldest one, still works but was challenging to set up, so … that’ s the one I’m going to go in the most detail here.

First of all, you need a Git repo that has hooks enabled … I lucked out when experimenting with this, having created a personal branch for the experiment and not realizing that not all repos had this enabled.

On the receiving server, you need a listener program; I found that uwsgi worked very well in this context.

You run it like this:

uwsgi — socket 0.0.0.0:3030 — protocol=http -w wsgi

The program wsgi.py needs to be in the same directory; it needs the following form:

import json

def application(environ, start_response):

… the rest is proprietary code and is left as an exercise for the reader.

How to alert the offender who broke the code? You could send an email, but some enterprise email systems get so much mail that’s it’s difficult to get a YOU BROKE THE CODE email to rise above the noise.

That’s one reason I use a simple Slack App that sends a message like “hey, @username, your push to branch mybranch, just broke the tests. Please revert/fix ASAP!”

Slack development in Python is also left as an exercise for the reader, but here’s one tip I got from Reddit … you have to use <{@username}>, not just {@username} to get the alert sound.

I hope this has been helpful for automating your own tests …

--

--