Categories Tags

Blog

Testing in general is a process that is normally left really in a partial state. The problem with this fact is it normally leaves things up to users or testers to find. And then, once found, the cost to fix the bug could be huge and hypothetically speaking, could touch various other parts of the application.

This is where unit tests and integration tests come in handy! Since this is a fairly broad topic, I am going to start by just talking about Unit Tests.

By definition, unit testing is a software testing method by which individual units of the source code are tested to determine whether they are fit to use.

So let's start from the beginning. What is a unit? It is the smallest testable part of an application. In procedural programming this could be an entire function, or as much as an entire page / section of code. In object oriented programming, these either an interface, or could even be a class.

But writing unit tests is still me writing code how will it help in the long run since it's taking away from the development of my site? It will help in the long run. I've had several occasions come up when I go to change "one small thing" which then ripples through and breaks other pages that touch this one unit. Essentially you are building your first layer of protection against future potential bugs.

The nice thing about writing test cases is it also allows you test things that may occur on the fringe cases. This will help to ensure that everything will should act as it's supposed to even in the strangest of situations. One of my favourite testing strategies (although admittedly I rarely do it), is actually test driven development. With Test Driven Development, you start coding by knowing what you want the end result to be (for your unit of work). You actually write tests for it and expect it to fail. If it doesn't fail right out of the gate, then your test may not actually be doing anything/finding anything useful. Then as you work your way through the development of this unit, you run your tests. Are all of your tests passing? If they aren't, then you know that you still have some work to do. However, if everything passes, then you know your application should work for at least all of your known cases. Which if you set up your tests correctly, should give you good confidence in the code.

The nice thing about writing these unit tests is that once you find a bug in any environment and resolve it, you are then able to actually write a unit test in order to actually test for that case so, if you change some more code, you don't re-introduce that bug.

With PHP, I, like most people, use PHPUnit as the primary unit testing software. Not only because it's built into Laravel and Laravel actually has helpers built on top to make the testing process even easier!

Although writing these test cases can sometimes be a big pain in the butt, if you do it correctly it can help you to spot issues earlier on in development before the time when it is "too late".

Hopefully this comes in handy for you!

Posted in php

Tags:

My anniversary for owning IcePets.com is coming up fairly soon (August 8th) and all I can say is wow has it ever been a ride so far.

I had been working as a freelancer with them for a little over a year, so I knew exactly what I was getting into.  Some very bad legacy code which was pieced together (and still holding fairly strong) with super glue and duct tape.  When going through the code, I noticed numerous back doors into the site that a previous programmer had built in for "security reasons".  AKA, in case they were banned, they would be able to make their way back into the site.  Those were patched, and the user was banned.  But here I was, owning a site and working with a bunch of people who I now call my friends with no idea the full vision.

So, my first order of duty was to bring the recode up into the foreground because the site wasn't really moving anywhere fast because I knew if this site was to be anything, the recode would bring a definite life to it.

Laravel was just breaking through the headlines on the PHP front when I had started working on the site.  But not only that, I was just working through the framework at the time and was entirely overwelmed!  There was so much going on, I knew it was all good and neat but just so much stuff!  But, I managed to power through it.  I started building the site up with Laravel 3.  A month later I heard that Laravel 4 was getting ready to be launched and it had some fairly substantial changes in it (aka - don't bother even trying to upgrade, just re-implement (copy and paste code) and build it up that way.

I was a little hesitant, but decided it had to be for the best.  That was when I was first introduced to "composer".  I had always dreamed of a way to easily incorporate other open source work into my projects, but never really knew a way.  This in itself was confusing!  Finally I managed my way through that hump and then came the next releases of Laravel (4.1 and 4.2).  These were fairly big.  By this point in time, I had already really started to focus on coding lots of the features. There were things I felt were clunky but it worked.  But something felt wrong.

When Laravel 5 came around, I decided to revisit the entire framework that I had thrown together to build IcePets version 2 (yes - a bit of a framework on top of the framework).  So, I started from scratch again.  This was ok because this time I knew it felt cleaner.

The last two years have been such a learning experience for me both technically and with leadership skills.  Looking back when I had originally thought about my very lofty goal of finishing the IcePets recode in a year, I realize how oblivious I was.  And, to be honest, I'm glad I didn't make that personal goal.  The technical learnings that I have picked up through the multiple iterations through the code, has slowed down progress on the site, but it has also opened my mind to way more options which I never even thought was possible.

I would like to say thank you to both the IcePets.com staff members as well as all of our loyal members who stick with us through this recode.  The best thing about the recode to me is the excitement it brings to me each and every time I think about it.  There are so many opportunities for us to morph the site into something substantially better than it currenlty is.  Once the recode is done, I think you will love the site and it will be a great place for all of us to bond as a community!

Thanks for reading!

Posted in icepets

Tags: