I can’t count the amount of times people have told me to add unit tests to my code. Wikipedia describes unit tests as:
In computer programming, unit testing is a software testing method by which individual units of source code, sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures, are tested to determine whether they are fit for use.
Basically, you test part of your code, app or site with a certain input and you know what it should respond with if everything is working properly. Before I would do this manually by simply using my websites and apps. For example I’d add a trip to my Nomad List profile every week any way, and sometimes it’d bug and I’d have to fix it. More often actually I get tweets telling me something is broken:
@levelsio Bug: searching for "city, state" should show results — right now only "city" does. pic.twitter.com/BdcX40Or3T
— Phil Freo (@philfreo) May 1, 2017
I get them all day:
@levelsio heads up https://t.co/7T5vCJewTO pic.twitter.com/YI3J0WnPqI
— Tanay (@theanarchist) May 23, 2017
And it’s amazing:
@levelsio Hey, in case you haven't noticed yet. Icecream chat is behaving bit wonkily when creating a new channel. https://t.co/DSKABuqpXn
— Kuldar (@kkuldar) May 23, 2017
We need….robots!
But having a robot do this for you EVERY single minute helps. It makes it faster. A robot won’t cover every problem yet, but it gets pretty close.
I tried all these unit testing suites, and like always, it’s all just too complicated and convoluted for me. So I thought, why not try something simpler. I was already using an app called Uptime Robot which pings my servers every few minutes to check if they’re up. But they also had a feature called “Keyword” which opens a page every minute, checks if a keyword that you specify exists. And if it doesn’t alerts you.
Enter UptimeRobot
What keyword do we use though? For most cases I decided on simply . Why? Because if a page doesn’t show the closing HTML tag anymore, it probably means it fatally error’ed somewhere in the middle, or it didn’t load at all. That means the alert will hit and it will signal me.
I also added a few more specific ones.
The Taipei city card page should obviously show the keyword “Taipei”:
The Bangkok chat should have “Bangkok”:
If you search for “Welling”, the city Wellington should show up:
If you post a job on Remote OK to preview it, the JSON should reply with success:
I have about 40 test cases now and will add more when I can think of more. The cool thing about Uptime Robot is that it has a wide array of alert outputs. It can send you an email, a Twitter DM, a Pushover notification, a push notification through its iOS app. But most importantly SMS. Wherever I am in the world I always have a backup phone with my main SIM card in it. That means if I’m in sub-Saharan Africa or Los Angeles or Bali, I’ll know when my sites are not working properly and I’ll be alerted WITHIN 60 seconds! How cool is that? Pretty cool I think 😀
I made two videos on Twitter to show how the system works:
✨I've built 37 test cases that check if my sites are working properly w/ @uptimerobot and SMS me if they're not, here's how it works (pt 1) pic.twitter.com/nB90v7ws5c
— Pieter Levels @ (@levelsio) May 23, 2017
✨I've built 37 test cases that check if my sites are working properly w/ @uptimerobot and SMS me if they're not, here's how it works (pt 2) pic.twitter.com/YKfeiozrXj
— Pieter Levels @ (@levelsio) May 23, 2017
It’s not the “proper” solution but it works for me. I know it’s limited, for example it doesn’t let you test entire sequential flows of user patterns (like a user clicking Join, then entering their username, then paying etc), but it’s good for basic testing. And it generally saves me time instead of using convoluted testing suites. Also, the best thing is, unlike test suites, it has email, push and SMS alerts built-in.
And I’m not the only one who gets alerted. My server and sys admin person also gets an email, DM and SMS and can go and fix things if I’m not available, like when I’m dancing to bad music dancing on a beach in Bali! At least now I’ll know, while I’m drinking fake whiskey, my server is down too! Haha.
This ties into my pursuit of automating every last part of my sites. I’m pretty close. Remote OK is 100% automated now, and Nomad List is at about 90%.
Let me know your feedback on Twitter 🙂
P.S. I'm on Twitter too if you'd like to follow more of my stories. And I wrote a book called MAKE about building startups without funding. See a list of my stories or contact me. To get an alert when I write a new blog post, you can subscribe below: