Database Testing
Database Testing
Overview
The database is a software subsystem that provides an efficient way to store user data and allows requesting it via a
structured query language known as SQL.
Not only does it stores critical business information but also functions as the backbone of an entire application.
Hence, database testing is essential for software testers to ensure the system is working correctly.
Importance of DB Testing
Database testing is a means to validate the data stored in the database, objects controlling data, and the functionality
wrapped around it. The databases use objects to manage data like tables for storage, views for representation, and
functions/triggers for manipulation.
Scope of DB Testing
○ Database objects which include tables, views, and stored procedures.
○ Validation of data being entered and getting stored in the database.
○ Make sure the system is honoring the constraints and data changes (insert/delete/update) are reflecting correctly.
○ Ensure the system can execute end-to-end database transactions and support concurrency.
○ Testing of database migration to ensure compatibility across different versions.
○ Verify the performance of database indices, triggers, and procedures.
○ Security compliance testing to rule out any unauthorized access or any threats to data.
Common Validations in DB Testing
○ Data mapping.
○ ACID (Atomicity, Consistency, Isolation, Durability) properties validation.
○ Data Integrity.
○ Business Rule Conformance.
Data Mapping
○ CRUD (Create/Retrieve/Update/Delete) event at the backend.
○ So here the tester should ascertain if the right event gets fired and finished successfully or not.
ACID
ACID is an acronym for Atomicity, Consistency, Isolation, and Durability. It refers to confirming the four properties (as
mentioned) against each database transaction.
a. Atomicity – It means that all Database Transactions are atomic. They can end in one of the two i.e. Success or
Failure.
b. Consistency – It indicates that the database state will remain valid after the transaction gets completed.
c. Isolation – Multiple transactions shall run without impacting each other and won’t hinder the database state.
d. Durability – Committing a transaction shall preserve the change and will not lose it due to any power loss or
crash later.
Basic Checklist
The tests are taking care of all the backend tables used for each requirement.
If the application/database is using status flags, then tests should verify each of them.
Tests cover the triggers/stored procedures with combinations of input and expected output parameters.
Tables might have columns with default values, tests should check them too.
Test environment should include a copy of the database. and it should execute have tests on a test database of realistic size and complexity.
The transactional information from the application should be stored in the database and it should provide correct information to the user.
Only completed transactions should be stored and all incomplete operations should be aborted by the application.
Access authorization to database should be maintained. No unapproved or unauthorized access to user information should be provided.
Structural Database Testing − It deals with table and column testing, schema testing, stored procedures and
views testing, checking triggers, etc.
Functional Testing − It involves checking functionality of database from user point of view. Most common
type of Functional testing are White box and black box testing.
Nonfunctional Testing − It involves load-testing, risk testing in database, stress testing, minimum system
requirements, and deals with the performance of the database.
MySQL Specific
{DESCRIBE | DESC} table_name;
SHOW TRIGGERS
SHOW TABLES;
The MySQL DDL gets involved with the schemas and explanations of database to display how the database data
should exist in the server.
The DDL commands are significant for expressing and altering the structure of database tables, schemas, or objects
CREATE Command
ALTER Command
DROP Command
TRUNCATE Command
MYSQL DML Commands
DML is an abbreviation of Data Manipulation Language.
The DML commands in Structured Query Language change the data present in the SQL
database. We can easily access, store, modify, update and delete the existing records
from the database using DML commands.
Following are the four main DML commands in SQL:
SELECT Command
INSERT Command
UPDATE Command
DELETE Command
MYSQL DCL Commands
DCL (Data Control Language)
REVOKE: This command withdraws the user's access privileges given by using
the GRANT command.
There are certain commands present in SQL known as TCL commands that help
the user manage the transactions that take place in a database.
COMMIT. ROLLBACK and SAVEPOINT are the most commonly used TCL
commands.
Stored Procedures
DELIMITER //
BEGIN
END //
DELIMITER ;
BEGIN
statements;
END //
MYSQL Cursors
A database cursor is a responsible control structure that allows traversal over the
data in a database using the DECLARE, OPEN, FETCH, and CLOSE functions.
Executing a stored Procedure
CALL stored_procedure_name(argument_list);
To check whether the data is well arranged and logically placed in the database.
To ensure that the data values are being placed correctly in their respective tables or columns.
Verifying and validating the correctness & integrity of the data, stored in the database.
Whether data reflecting at front-end and stored at back-end is correctly synchronised and updated.
Whether the data or values, fetched from the front-end is being correctly and successfully getting stored at back-end.
Checking the compatibility of the data with the software and hardware, especially the outdated or obsolete one.
BD Testing Checklist - Stored Procedures
Stored Procedures:
Whether the execution of stored procedures or functions are outputting correct and
reliable result sets.
Manual execution of the stored procedures, updates the database tables.
To ensure that correct and standard coding conventions is adopted and followed for the
stored procedures.
Does input data is able to encompass all sort of loops and conditions.
To ensure proper and standard error and exception handing mechanism.
Verifying and validating the attributes and parameters associated with each procedure.
Evaluating the working or execution of all stored procedures in the presence of blank or
empty database.
BD Testing Checklist - Triggers
Triggers
Similar to stored procedures, adoption and implementation of correct and standing
conventions for triggers, by the developers is being evaluated.
To ensure that the execution of a trigger updates the data in the database,
successfully.
If the triggers are being executed for the DML transaction.
Checking the execution of a trigger in the event of addition or deletion or update in
the data.
To check whether the execution of a stored procedure is followed by the firing of a
trigger.
BD Testing Checklist - Field Validation
Field Validation:
Whether the database system is allowing the entry and storage of null data value
or not.
To ensure the appropriate and sufficient length of each field to import and
accommodate respective data value of varying range.
Verifying and validating the data type for each field against specified and given
specifications.
To check whether all identical fields have similar name throughout the database
and tables.
To locate any computed field(if any) in the database and tables.
BD Testing Checklist - Constraints
Constraints:
Whether the primary key and the foreign key constraints is specified and created
for each table or not.
Proper and valid referencing of foreign key between the database table has been
done or not.
Whether the null value is being accepted as a valid input both for the primary and
the foreign key.
Database performance in terms of time taken, for the execution of lesser number
of queries for small set of records.
Data Duplication
Data Migration