📣Postmark has been acquired by ActiveCampaign
x

Automated testing — organizing data and test cases

I’ve been using Selenium for different types of automated testing for some time, and I decided to share my thoughts on the importance of organizing data and test cases when doing automated testing.

Preparing data

When you are testing existing or new features of your application, it’s very important to have adequate testing data. The more data you have, the more bugs can be spotted early in the testing/development stage.

Having good test data is very important for both manual and automated testing. Before writting the tests, it’s wise to think through and see which data you will need to run the tests.

Some of the questions you need to ask yourself before starting automated testing are:

  • What functionality do you want to test?
  • Will you be able to test the functionality (limits of automated testing tools, etc)?
  • What data do you need for the testing?
  • How do you organize the test cases to be reusable and easy to use?

Before you start writting the test cases, think of all the data you will need and the stages of the testing which will require it. This can save a lot of time and make your automated tests consistent. You will need to have data which is needed in all stages of testing (like login credentials), and data which would be used during testing. Managing data will probably include 4 steps:

  • Prepare data needed in all stages of testing
  • Prepare test data which would be used during testing
  • Delete all data used during testing
  • Delete all data needed in all stages of testing

By following the steps mentioned above, you will have the data you need during the tests, and you will leave the application data intact - by deleting all data you used during testing, you will get the system back in the state in which it was before testing. You should always make sure to set the application back to the original state, this way your automated tests can be run unlimited number of times and would not leave the application in an undesired state.

Reusability

When writing test cases, though you don’t need to be an expert programmer, try not to repeat the code too often. You would probably want to run those test cases daily, and updating a bunch of repeating code in your test cases can be hard and time consuming.

Always try to separate the parts which you will reuse often in your test cases. For example, a developer changed a part of the code, which you test often. If you did not repeat your code, you would probably need to update your test cases in only one place. Same goes for data. I usually store data like login credentials and automated testing settings in separate files, so I can easily update them later.

Use meaningfull names for the test cases

Using meaningfull names for the test classses and test cases can be handy too. It will allow you to find the code you need to update easier. I usually call the test classes by the name of the section I am testing. For example, in web applications, I use the name “Account” for test class which will contain all related test cases to “Account” section in web application. This way I can also find the test class easier when I want to include/exclude it from the test suite for the next run.

Always be prepared

The most important part of automated testing, as for any other type of testing is being prepared: being familiar with the system which needs to be tested. Thinking through all the actions needed to create automated tests and organizing data and test cases will help you create a test suite (test cases) of high quality.