0% found this document useful (0 votes)
5 views

Database Testing

The document discusses database testing. It covers an overview of databases and why database testing is important. It then discusses the scope of database testing including objects, data validation, transactions, migration, performance, and security. It also discusses common validations like data mapping, ACID properties, data integrity, and business rules. Finally, it provides examples of database testing for specific tools like MySQL.

Uploaded by

Suresh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Database Testing

The document discusses database testing. It covers an overview of databases and why database testing is important. It then discusses the scope of database testing including objects, data validation, transactions, migration, performance, and security. It also discusses common validations like data mapping, ACID properties, data integrity, and business rules. Finally, it provides examples of database testing for specific tools like MySQL.

Uploaded by

Suresh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

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.

Name of the database.

Name of the log file.

Disk space allocation for databases.

Names of all tables, columns, and their types.

Null value checks.

Verify keys (primary/foreign), indexes, and data types of columns used.


Sample Database
Tools

DDL => Data Definition Language.


DML => Data Manipulation Language.
DCL => Data Control Language.
Items to Plan for in DB Testing
requirements related to
data migration or
database performance.
A good source for eliciting database requirements is the database design
documents.
The scope of DB Testing would be on several aspects
- Accuracy (In terms of financial sensitive information)
- Speed and Space (If its transaction intentional)
Types of Testing in DB
● OLAP
● OLTP

The primary purpose of online analytical processing (OLAP) is to analyze


aggregated data, while the primary purpose of online transaction processing
(OLTP) is to process database transactions.
Items planned in a DB Test plan
Schema and the data.

Limit the scope of your database test

Test environment should include a copy of the database. and it should execute have tests on a test database of realistic size and complexity.

SQL and database tools specific to your database technology.

The transactional information from the application should be stored in the database and it should provide correct information to the user.

Information should not be lost when it is loaded to database.

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

[{FROM | IN} db_name]

[LIKE 'pattern' | WHERE expr]

SHOW TABLES;

SHOW PROCEDURE STATUS [LIKE 'pattern' | WHERE search_condition]


MySQL Specific
DESCRIBE yourDatabasename.yourTableName;
show create table business.student;

# Selecting all the unique Constraints in a table


SELECT DISTINCT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE
TABLE_NAME = ’yourTableName’ AND CONSTRAINT_TYPE = ’UNIQUE’;

select COLUMN_NAME, CONSTRAINT_NAME, REFERENCED_COLUMN_NAME, REFERENCED_TABLE_NAME


from information_schema.KEY_COLUMN_USAGE
where TABLE_NAME = 'yourTableName';
MYSQL DDL Commands
MySQL DDL defines the Data Definition Language, a subgroup of SQL commands among four: DDL, DML, DCL, and
TCL. Since,

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)

GRANT: This command gives users access privileges to the database.

REVOKE: This command withdraws the user's access privileges given by using
the GRANT command.

COMMIT: Commits a Transaction.

ROLLBACK: Rollbacks a transaction in case of any error occurs.


MYSQL TCL Commands
TCL stands for Transaction control language.

A single unit of work in a database is formed after the consecutive execution of


commands is known as a transaction.

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 //

CREATE PROCEDURE GetAllProducts()

BEGIN

SELECT * FROM products;

END //

DELIMITER ;

CREATE PROCEDURE procedure_name(parameter_list)

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);

● Use the CREATE PROCEDURE statement to create a new stored procedure.


● Use the CALL statement to execute a stored procedure.
● MySQL stores the stored procedures in the server.
MYSQL Triggers
1. mysql> USE mysqltestdb;
2. mysql>SHOW TRIGGERS;

SHOW TRIGGERS FROM mysqltestdb


WHERE table = 'employee';
BD Testing Checklist - Data Integrity:
Data Integrity:

To check whether the data is well arranged and logically placed in the database.

To evaluate the consistency of the data.

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.

To locate and get rid of redundant and useless data.

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.

To check, if no data valued is present outside the table.

Whether data outside the table, could be modified or not.

Whether database is able to store or export blank or null value.

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.

To ensure primary key data type of a table is same as to that of corresponding


foreign key of other table.
BD Testing Checklist - Transactions
Transactions:
To check out whether the correct transaction is being executed or not.
To ensure that the data is being committed on the successful execution of the
transaction.
To check that if the data is rollback in the event of transaction failure along with the
involvement of multiple variants of database.
To check whether the transactions are fulfilling the ACID (Atomicity, Consistency,
Isolation, Durability) properties.
To ensure that all the transactions is being called upon & executed by the
TRANSACTION Keyword.
BD Testing Checklist - Indexes
Indexes

To check the presence of clustered and non-clustered indexes to fulfil the


necessary need for a given table as per the business requirements.

To evaluate the size and length of the indexes.

Naming conventions for the indexes.


BD Testing Checklist - Performance
Performance

Database performance in terms of time taken, for the execution of lesser number
of queries for small set of records.

Database performance in terms of time taken, for the execution of queries


pertaining to comparatively large set of records.

Performance of database in the event of simultaneous and concurrent access to


data by multiple users.

To verify and validate the normalization of the database.

Time in retrieving or updating the data or records.


BD Testing Checklist - Security
Security
Verifying & validating the access and no access to database by authorized and non-authorized
users, respectively.
Verifying & validating the different permission granted to each different role, assigned for the
database.
Other security aspects comprises of evaluation of following features:
Authentication.
Confidentiality.
Availability.
Integrity.
Resilience.
BD Testing Checklist - Deployment
Data Redundancy

Data Duplication

Data Migration

Database timely backup & recovery management and plan.

You might also like