Skip to main content

Treating Test Code as Production Code

It's important when writing automated tests to remember that the code you write should be up to production standards, meaning any conventions that you have in place should be adhered to and that it should follow good design patterns.

Too many people often say why does it have to be as good as production code, it's "Only" a test, so long as it passes then that's fine...

To answer this we need to look at why we want our tests to be written in such a structured and efficient manner:

- Maintainability - by making the test code structured and efficient, it becomes far easier to maintain and in doing so changes in the future can happen quickly as the test isn't linked to anything that it shouldn't be and it's easy to understand for a new set of eyes.
- Durability- Again by making the tests structured they should be resistant to changes, if you change a variable name for instance then it shouldn't effect the unit test unless it absolutely has to.
- Flaky - We've all been there, had tests flaky and failing when they really shouldn't be failing, you run it again and hey presto! it works!

And finally, and perhaps the most important:

- Defects - The main reason in writing automated tests is to identify defects earlier and often and quickly. If we ignore the above, then we'll end up ignoring tests or in some cases removing tests that are flaky, and if we're removing tests then the defects that the tests were put into find, could quite easily work their way into production which is not what we want.

I know maintaining tests is time consuming and people struggle to comprehend the value in keeping tests maintained and up to date, until of course bugs are found in production, then if only we had a time machine to go back and run the tests that were removed or commented out!

So this is why I believe that test code is just as important (and you could easily argue that it is more important) than the actual code that it tests.

Anyone agree/disagree????


Comments

  1. At this link you can find even more great writing tips and tutorials for bloggers.

    ReplyDelete

Post a Comment

Popular posts from this blog

Testers: Be more like a Super-Villain!

Who doesn't love a Super Hero? Talk to my son, and he'll tell you how much he loves them, talk to many adults and they'll say the same! Deep down, we all love to be the Super Hero, we all want to save the day! However, I want to talk about the flip side of Super Heroes, the Super Villains... I often play Imaginext with my son, and I (unfortunately?) am nearly always the Super Villain! Be it Lex Luthor, Joker, Two Face, Mr Freeze or The Riddler! These are all great characters and great Super Villains, but why would I want to write about Super Villains? A while ago where I worked, we had a few Super Heroes, people who would be able to come in and "fix" things that had broken and help deliver projects on time. We then shifted, we decided to do away with the Super Hero culture and try and prevent from being in that position in the first place, whilst we didn't go as far as wanting to hire Super Villains, it's definitely a story that has stuck with me and t...

QA is Awesome!

No real point to this post other than I have had the song stuck in my head and figured I could change it slightly and quite easily make QA is Awesome! Oh and I haven't even seen the movie all the way through! But for some reason that song is incredibly catchy! Not much point to this post in fact, just thought I'd put it out there :)

What we (Asos Testers) are working towards this year...

At Asos we have a large testing team (30+ testers), they all work within their development teams, and the way development teams work can vary and understandably so. Helping the 30+ testers we have a number of Test Leads, of which I am one, recently we (the leads) all got together to come up with a plan of things that we feel we need to work on/define/have an idea of how to approach them for the next year to help improve our testing standards across the boards and improve the skillset of testers within the teams. To help with this we got together and came up with a mindmap, the plan going forward is for us to take ownership of one of the areas and come up with a strategy/approach/implement actions to help improve the areas and define whatever is needed. There's a lot there, and I'll probably write seperately about each one, and what we're doing, as it's always good to share ideas and get feedback... so watch this space!