Tip Tuesday: Storing test data in JSON file

Code on screen
Photo by Sai Kiran Anagani on Unsplash

Today’s Tip Tuesday article is about storing test data in the JSON file to improve and expand the diversity of tests in your automation. 

You use Page Object Model to separate your tests from the pages to improve test automation performance, but do you separate your test data from the tests? One way to improve and expand test automation is by keeping your test data (e.g. users, attachments, test content, etc.) in a JSON file that you can pull from. This allows you to create additional, diversified tests easily. 

So how and why would you separate your test data? Let’s start with the why. By separating your test data in a separate file you can update it as you needed to without having to update your tests. You can also use the data interchangeably to change your tests. Let’s look at an example. 

{ 
   “Users”: { 
      “user1”: {  
         “email”: “[email protected]", 
         “password”: “pa55w0rd1” 
      }, 
      “user2”:{ 
         “email”: “[email protected]”, 
         “password”: “password2”
      } 
   } 
} 

In this case you have two users that you can use for login testing. You can also mix user2 email with user1 password for negative testing.  How can we take it further? We could add additional details about the users, such as the name and a picture. Let’s take see how that might look. 

{ 
   “Users”: { 
      “user1”: {  
         “email”: “[email protected]", 
         “password”: “pa55w0rd1”}, 
         “first_name”: “Joe”, 
         “last_name”: “Smith”, 
         “profile_picture”: “joe.jpg” 
         }, 
      “user2”:{ 
         “email”: “[email protected]”, 
         “password”: “password2”, 
         “first_name”: “Jane”, 
         “last_name”: “Jones-Smith”, 
         “profile_picture”: “jane.jpg” 
         } 
      } 
} 

You now have your users removed from the tests which allows you create tests around user creation, login, and updating users.  With JSON files you don’t need to pull or use all of the fields that are listed, this means you have more flexibility with creating positive and negative tests. More importantly, you’ll be able to write cleaner code that is more repeatable.

Tip Tuesday is a short format article focused on improving test automation, testing, or leadership that come out on Tuesday Morning. Keep an out for future articles covering test automation, testing, and leadership.

Connect with me

If you liked this post, take a quick minute to sign up.

Leave a Reply