Managing the test data for functional tests
By: Akshay Maldhure
Tags: Quality Assurance, Test Data Management, Software Testing, Software Development

Background

Most functional tests need test data to work. Consider this classic example of an end-to-end login test for an application in a “testing” environment, where the application services are typically configured to talk to a real database system. We need to provide the credentials of a user for such a test. So our test flow should either create a user or use an existing one. This is where accessing and managing the test data comes into picture.

This article talks about one of the ways of de-tangling the test data dependency and management part from the tests.

Problem

The task of creating, accessing and managing the test data during test execution has below challenges.

Unavailability of a data mocking system: You need to rely on one or more “real” downstream systems for data creation. Complexity in creating new data: No straightforward way of creating data (e.g. lack of APIs, multiple systems needing updates after data creation, etc). The state of test data matters for the tests: The test data may not be re-usable if we are unable to reset its state after test execution. Resilience: Some system(s) might fail to create new test data.

Approach

In order to address this problem, we came up with an approach of storing the test data in a centralised data store, which was used by our automation suites for any test data needs during test execution.

We achieved this by building a test data management system (TDMS) that uses an Elasticsearch instance as a data store.

In the application testing process, there are a set of test cases that aim at validating the test generation flows. We leveraged such tests to seed our data store with newly generated test data in a specific format (schema) either through automation test hooks or through cron (maintenance) jobs.

So going back to our original example of a login test, the most fundamental data entity could be a user. So we could choose to store the test data on a corresponding Elasticsearch index called “user”, in which documents look like below.

{

"id": 1,

"personalDetails": {

"firstName": "John",

"lastName": "Doe",

"age": 28

},

"accountStatus": "active"

},

{

"id": 2,

"personalDetails": {

"firstName": "Stephen",

"lastName": "Williams",

"age": 30

},

"accountStatus": "suspended"

}

Now we can have the tests query TDMS for the data as per the requirement. For example, get an active user for testing login success or get a suspended user for testing login failure.

A test data management system showing the flow of test data with the application under test

However, there are a couple of problems with this approach.

The test data state will not be updated in TDMS after test execution. Multiple tests are likely to end up using the same test data during execution.

In order to address these problems, we added a data lock mechanism to prevent this from happening. Once the data is locked, no other tests can reuse the data set until the data is refreshed in TDMS.

Future plans

While this approach has solved our burning problem of managing the test data, we have plans to overcome some of the shortcomings and make it as a holistic system useful for the entire organisation by: