Database Testing: A Full Guide

Blog TOC Banner

Database testing is the process of evaluating the accuracy, reliability, and performance of a database system. Its purpose is to ensure that the data stored there is consistent, valid, and can be correctly manipulated for business needs. The components to be tested are usually database schema, tables, and database triggers. Testers leverage SQL queries, data comparison tools, automation frameworks, or load testing tools to examine the data integrity, validity, security, performance, and structure.

Why Should We Test Our Database?

1. Prevent issues during data mapping

These scenarios result in a misunderstanding between the two systems, causing disastrous consequences. Imagine a bug occurs in the patient record database of a healthcare billing system. When retrieving data in the patient database to calculate their billing, the wrong data field was chosen, and patients ended up receiving bills for services they never received in the first place. If this occurs at a wide enough scale, the impact will surely be costly to reverse.

2. Verify data accuracy and integrity

Data mapping issues can also originate from issues with data accuracy and data integrity. Data accuracy is how correctly the data represents real-world scenarios, while data integrity is more about its consistency throughout the entire life cycle (from data entry to storage and retrieval). We know that data undergoes so many changes throughout its lifecycle, and those changes can totally bring in new errors that eventually lead to issues in data mapping.

There are usually 4 types of data integrity that database testers need to pay attention to:

3. Ensure accuracy with business requirements

There is no point having millions of accurate but irrelevant data points. While not a particularly technical aspect of DB testing, conformity with business requirements is still an important indicator of data quality. Testers all have a clear understanding of business requirements since they are involved in the Requirements Collection process. These requirements should be written as a checklist, then testers and stakeholders can sit together to determine how to test each item in the list through a comprehensive methodology.

ACID Properties Of Database Transactions

Before further delving into each of these properties, we need to define the concept of a “transaction” in a database.

A transaction is a logical unit of work that consists of one or more operations performed on a database to access and modify its content. For example, in a retail inventory system, when a product is sold, the database needs to update both the available quantity of the product and the sales record. These updates are executed within a transaction.

ACID properties are a set of characteristics that ensure reliable and consistent transactions in a database system. Essentially they are the 4 major rules for a good transaction in any database, and testers can base their test plan on those rules. ACID stands for:

ACID properties | Katalon

ACID Properties Explained

1. Atomicity

Every transaction in the system is treated as a single, indivisible unit, hence the term “atom-icity”. Either all of the operations in the transaction are successfully completed, or none of them are applied. There is no middle ground.

Following this property, there are only 2 outcomes for a transaction:

Atomicity transaction outcomes

2. Consistency

The correctness and integrity of the data and database’s state must be maintained before and after a transaction. In other words, the existing rules defining relationships between data fields must be kept the same when the database is brought from one state to another. The relationships, or integrity constraints , that should not be violated may include:

Suppose we have a banking application with two tables: Accounts and Transactions.

An integrity constraint states that the balance in the Accounts table should always be consistent with the sum of transaction amounts in the Transactions table for that account.

Initial State:

Transaction 1:

Transaction 2 (Concurrently):

Consistency Check:

At this point, the consistency property ensures that:

Transaction

Account Balance

(Accounts Table)

Transactions Table

(if both commit concurrently)

Sum of transaction amounts matches account balance

3. Isolation

Isolation means ensuring that each transaction is executed in isolation from other concurrently executing transactions. Even though multiple transactions may be occurring simultaneously, each transaction should not interfere with others. This prevents issues that can arise when one transaction reads or modifies data that another transaction is in the process of modifying, such as:

Isolation levels are therefore necessary to govern how transactions in a database interact with each other, preventing such scenarios from happening.

4. Durability

Durability guarantees that once a transaction is committed, its changes are permanent and will survive system failures, crashes, or power outages. Even if the system restarts or fails, the database will be brought back to a consistent state by applying the committed changes from a durable storage medium.

Types of Database Testing

1. Structural Testing

Structural testing, also known as glass box testing or white-box testing, focuses on examining the internal structure of the system (which is the database and its components in this case). The goal is to ensure that the database schema, tables, relationships, constraints, and other structural elements are designed and implemented correctly.

Several types of structural testing include: