5 Tips for Writing Automated Tests

 

So you want to write some automated tests, eh?

Here are 5 tips to help save you some time along the way.

1. Make a plan.

List

Take stock of your existing suite (if there is one). Are there tests that need to be updated? Tests that can be deleted? Clean that suite up first, so you’re not adding even more tests to an already cluttered collection.

Once you’ve finished housekeeping, figure out what tests you need to create and what those tests need to do. Write it down somewhere so you can track your progress.

Be willing to adjust the plan as necessary. You may determine that a particular test isn’t suited to automation, or that there’s something you didn’t consider and that you need to account for. That’s OK. The point is to go into test writing prepared.

2. Get in the zone.

Clock

Set aside blocks of time to write your tests.

It’s almost impossible to create an automated test if you can only devote 10 minutes to it here, 5 there. . . When you’re not working on a test for a continuous period of time, you end up spending time refreshing your memory to figure out where you left off each time you start to work on it again.

Likewise, limit distractions and interruptions as much as possible. Mark yourself as “Do not disturb” on your company chat app, close your email, and gosh darn it, get off BuzzFeed!

 

3. Be resourceful.

Resourceful

Reuse parts of tests you’ve already written whenever possible.

If there’s something that you do in multiple tests (like logging in, for example), create a chunk or “phrase” for that process that you can drop into other tests.

See if your automation tool allows you to store those phrases so you can modify the phrases themselves when necessary, instead of modifying every single test that uses them. If so, take advantage of that feature like nobody’s business.

4. Don’t wait until the end to try running the test.

Write your test in pieces and try running the test as you go along. Modify the section you’re working on as needed until it’s working as expected.

Get a piece working before moving on to the next one. This way, you can head off problems sooner rather than later.

5. Focus on one version of the test at a time.

Puzzle

Don’t try to do everything all at once.

If a test needs to work for multiple sets of test data (for example, multiple test user roles or multiple URLs), don’t start out trying to write it for all of them.

Write the test for one test data value and get that version working first, then expand to other variations.

I hope these suggestions help as you build out your automated test suite.

What are your favorite tips and tricks for writing automated tests? Please share!

 

About the Author:

CullynThomsonCullyn Thomson is a tester and technical writer at Tellurium, a cloud-based solution for collaborative testing and test management written in a “Plain English” automated scripting language.

You can follow Cullyn on Twitter at @CullynT and Tellurium at @te52app.

About the Author

Joseph

Find out more about @josephmckeating