A Beginner's Guide to Test Automation

If you’re new to automated testing, you’re probably starting off with a lot of questions: How do I know which tests to automate? Why is automated testing useful for me and my team? How do I choose a tool or framework? This article answers a lot of those questions—and gives you some more to consider!—so you have an excellent foundation for beginning your automation endeavors.

If you’re new to automated testing, you’re probably starting off with a lot of questions: How do I know which tests to automate? Why is automated testing useful for me and my team? How do I choose a tool or framework? The options for automated testing are wide open, and you may feel overwhelmed.

I want to help turn some of your “unknown unknowns” into “known unknowns”! The goal of automation is to create anti-fragile tests that are easy to understand, maintain, and hand off. I’ll get you closer to that goal by answering some questions that many of us had when we first started with automated testing, and I’ll also give you some additional questions that are good to consider.

Introducing Automation

Once you’ve decided to start automating, the next step is probably to introduce the idea to your team. Automation may not be the only work you’re doing, but it is going to be a lot of work! Trying to squeeze it in between your regular work means it probably won’t end up getting completed. In order to really succeed with automation work, you’ll need to get buy-in from the team to dedicate your time and effort toward it.

I started the conversation by explaining why automation is important and how it’s useful to our work. One of the things I try to establish with engineering teams is the idea that no single type of testing should bear the responsibility for quality. Different methods serve different purposes, and they are all part of the whole.

Automation can be useful for testing lower-risk functionality, which frees you up to focus on higher-risk, high-priority, or more complicated functionality. On the other hand, maybe you have some high-risk items that will need to be tested regularly, and creating automated testing for those items would create more confidence in them.

Our biggest risk as a team was transitioning from our existing monolith repository to a new microservices codebase. Offering to create automated regression tests had a lot of support from the team: engineers benefited because they could have higher confidence that their work wasn’t breaking anything, and our product owner had confidence that any breaking changes would be quickly found before releasing to production. It also benefited me, since I was now going to automate all the repetitive testing scenarios!

When you’re proposing automation, consider what the team needs are, then determine how you can include automation in a way that balances those needs. You’re more likely to get support if the benefits are more easily felt, so ask your product owner or developers what’s important to them. Overall, the goal is to make sure your automation efforts are supported by the team so you can focus on creating tests that support the team in turn.

Choosing a Tool

One of the most common questions when starting automated testing is “What tool or framework should I use?” The answer, as with many things, is “It depends.” There are several questions you’ll want to consider: 

  • Who is writing the automated tests?
  • What kinds of tests are you running?
  • For paid frameworks, does your department have a budget?
  • If the tool is open source, is there good documentation and community support?

If the developers are writing unit tests, they’re probably going to write them in the same language as the rest of the codebase. If they’re using PHP, they might look at PHPUnit; for JavaScript, they might check out Jest. The goal here is really to make it as easy as possible for developers to incorporate testing in their regular development workflow. So instead of being prescriptive about the framework they use for testing, the focus should be on helping them find the right tool for their needs.

When I’m considering automation tools, my main considerations are usually choosing between code-based and codeless, and open source versus paid.

In my role as a QA engineer, I’ve typically been responsible for QA and testing on multiple engineering teams at a time. It’s not feasible that I’d be solely responsible for automation on all of the teams, so I approach automation with the idea that the developers will also be contributing to these tests. That leads me to choose code-based frameworks, because it follows a pattern of working that the developers are familiar with, and it keeps the work in the same repo as the codebase. A codeless solution would mean learning a totally new tool, another login to keep track of, and testing that’s a bit removed from the codebase they’re already in every day. 

When considering open source versus paid, I’ve often run into budgetary restrictions that cause me to choose open source. In comparing open source options, I consider how actively the tool is maintained—are there lots of open, unanswered issues and pull requests? When was the codebase last updated? I look at the documentation and see how easy it is to install and start writing my first tests. If I can, I ask other testers if they’ve had experience with the tool and what they thought of it.

Keep in mind that your needs and situation may differ from mine. This information isn’t intended to tell you what your answers should be, but to give you things to think about. The goal is to consider what you need from an automation tool and understand how to sift through the options to figure out what tool meets your needs.

Writing Your First Test

When I started writing my regression tests, I was focused on getting the tests to pass—that’s the goal, right? I’d get one part of the user journey passing, and then start writing tests for the next bit. It was exciting to see the growing list of green checks every time I ran the tests. Eventually, I had our three main user journeys tested and passing. I was giddy with the power of automation!

I also had an enormous test file.

There are a couple of drawbacks to this. First, all the user journeys were being tested as a single test flow. So if something failed along the way, all of the subsequent tests were useless, because they would also now fail. It would also be much harder to update this file if something changed, because I’d have to go through every single step in all of the user journeys to see what else might be affected by the change. In short, I had created a fragile test.

To improve my automation suite and make it more resilient, I broke out the user journey into smaller chunks and placed those chunks into their own test files. It was a fairly tedious process, as I now had to rerun every test to make sure I hadn’t broken it in the extraction.

In my initial excitement over automating my tests, I’d also committed the basic authentication for our staging site. I figured I’d come back to the credentials with a proper setup later, because my focus was writing the tests and having them pass. Fortunately, I realized what I had done before I pushed my commits, and I was able to do some Git maneuvering to remove the committed credentials.

This experience, tedious as it was, taught me the importance of outlining my tests before I start writing them. An outline gives me a better estimate of the time and effort that creating the tests might take, and it can help me prioritize which are most important to complete if my time is more limited. I also realized that dealing with credentials securely should be one of the first tasks to go in the outline.

It’s important not to get caught up in the idea that you need to write tests that pass. Focus instead on creating your tests so that they’re easy to run and maintain and are as secure and anti-fragile as possible.

Best Practices

Security and test structure are just a couple of things you’ll need to think about as you’re writing automated tests. Here are some of the questions I didn’t know I needed to ask when I first started:

  • Do the tests depend on each other for data?
  • Are failures easily understood from the logs?
  • How easy would it be for someone else to update your tests?

Ideally, your tests can be run in isolation from each other. If they depend on other tests for their data, a failure in one test can have a cascading effect. Whether you’re using fixture data to test at the unit or service level, or testing a user journey at the UI level, make sure the tests can be run independently. Not only does this help you create anti-fragile tests, it makes it much easier to pinpoint failures when they do occur.

And you will have failures, but that doesn’t mean you wrote a bad test. On the contrary, this means you wrote a useful test that caught a failure! Once a test has failed, you need to investigate why, and there are ways to make this easier on yourself.

Don’t just stick to the happy paths as you’re writing tests—make sure you’re including error messaging. If your test doesn’t have an error message, a failure only tells you that the test didn’t succeed; it doesn’t tell you why it wasn’t successful. Having a clear error message helps you narrow down where the failure occurred. For instance, throwing an error like “Service didn’t return the expected 200 response” is much clearer than “It didn’t work” or a silent failure.

By the same token, your test descriptions and test steps should be written for clarity. Test output acts as a log, so you should write your automation with that in mind. Consider a description like “It 404s” versus “Sends a 404 if the file does not exist.” The first one is generic, providing no information beyond expecting a 404. The second example is much more informative, because it tells me that I’m checking for an expected 404 response when the test doesn’t find a file.

Having clear steps and error messages also makes it much easier for the test suite to be maintained and updated, whether it’s by you or someone else. Once the automation is in place, it’s likely that other people on the team will start contributing as well. If you’ve already established a good pattern of writing tests, it’ll be relatively simple for someone else to pick up where you left off.

Go Forth and Automate

The important thing to remember is that it’s not about the One Right Answer to anything. It’s about understanding the questions you’ll need to ask, and how to find the answers that will work for you and your team. Getting support for automation work, creating a practical infrastructure, and choosing the right tool for your needs will give you an excellent foundation for beginning your automation endeavors.

So go forth and automate with confidence. You may not have all the answers yet, but having the questions is a really good start!

User Comments

Dolly Agarwal's picture

Article worth reading before one starts to automate :) 

March 25, 2019 - 10:25am
Angela Riggs's picture

Thank you! :D I learned these things the hard way, so I'm glad to help other people learn these things ahead of time!

May 23, 2019 - 12:06pm
Joe Dwyer's picture

Thanks Angels this was a great article and a reminder of items to consider. I liked your theme throughout the article of choosing what is right for the team, to get team buy in and to do the upfront work before automating. Everyone wants to automate and management pressure can push teams to jump in only to fail down the road when maintence outweights the benefits.

I would like to add another item if I may, careful converting manual tests to automated ones. There may be some good tests there but don't just automate them because they exist. Create a set of criteria for your automatd tests and use that as a priority to automate the existing manual tests.

March 26, 2019 - 1:54pm
Angela Riggs's picture

Totally agree - there's often a push to just "automate everything", which isn't a good goal. Better to consider which tasks would be better served if they were automated!

May 23, 2019 - 12:08pm
Joe DeMeyer's picture

Well done, Angela!  This is the most responsible article on test automation I've read in quite a while.  I appreciated the focus on testing rather than a tool, and on isolation rather than end-to-end.  Long live anti-fragile!

April 1, 2019 - 7:52pm
Angela Riggs's picture

Thank you! Anti-fragility isn't talked about as often as I think it should be, but it's such an important consideration!

May 23, 2019 - 12:08pm
John Hoge's picture

I wish the article contained more information regarding the "what to automate" identification process.   My experience is that teams autmate functions that do not return a great bang for the buck.  

May 23, 2019 - 12:04pm
Angela Riggs's picture

I was wary of being too prescriptive - the idea was to give people a starting point for concepts and questions to consider when they are first considering test automation. 

When you say "automate functions", do you mean unit testing? I think TDD is a great goal, and a really good way for developers to contribute toward useful automation.

May 23, 2019 - 12:12pm
Sapir Lyubinsky's picture

Great article Angela! Tests definitely make your life and everybody else’s easier. I liked the points you touched on in your article from your experience. Like you said, "finding the right tool is very important".

March 30, 2020 - 8:55am

About the author

StickyMinds is a TechWell community.

Through conferences, training, consulting, and online resources, TechWell helps you develop and deliver great software every day.