Professional Documents
Culture Documents
Table of Contents
INTRODUCTION..................................................................................................3
PRE REQUISITES.................................................................................................3
WHAT TO TEST?.................................................................................................3
TYPES OF DB TESTING..................................................................................................................4
BASIC OPERATIONS IN DATABASE TESTING..............................................................................................4
TESTING SPS.............................................................................................................................4
POSITIVE SCENARIOS.....................................................................................................................5
NEGATIVE SCENARIOS ...................................................................................................................5
TESTING TABLES.........................................................................................................................5
TESTING PROCESS........................................................................................................................5
TESTING FUNCTIONS.....................................................................................................................6
TESTING TRIGGERS.......................................................................................................................6
TESTING VIEWS..........................................................................................................................6
TESTING SQL JOBS.....................................................................................................................6
TESTING REPLICATION...................................................................................................................6
TESTING DATABASE BACKUP............................................................................................................7
SQL CODE COVERAGE FOR SPS......................................................................................................7
PERFORMANCE TESTING.................................................................................................................7
SECURITY TESTING.......................................................................................................................7
DATABASE TESTING PROJECT WITH VSTS DETAILS...............................................8
CREATING DATABASE TEST PROJECT...................................................................................................8
FOLLOWING TEST CONDITIONS WILL BE USED...........................................................................................8
TYPICAL SAMPLE TEST SCENARIO......................................................................................................12
BEST PRACTICES..............................................................................................15
Introduction
There are several reasons why we need to develop a comprehensive testing
strategy for your RDBMS:
Pre requisites
The person who is going to test should have permissions to connect to
required database server and database to execute automated tests. One should
have permissions to execute related SPs or operations on tables.
Configuration file will be used for connection strings, test data documents
path and sheet names etc..
What to test?
Following diagram shows all database objects which are to be tested.
Performance
& Security Tables
Stored
Procedures
Views
Functions DB
Triggers
Jobs
Data Backup
Replication Code
Coverage
Types of DB testing
1.Using Test project with database tests in Visual Studio Team Systems
2. Using normal test project with CSharp code along with ADO.net objects
3. There are also some tools like TSQLUnit, Empirix, RadView, SQLUnit, DBFit
and NDbUnit etc..
Insert: Inserting data into table(s) with the SQL Queries or executing SP can
be done.
Delete: Deleting the data from table(s) with the SQL Queries or executing
SP can be done.
Select: Selecting the data from table(s) with the SQL Queries or executing
SP can be done.
Testing SPs
In general, Stored procedure can be used for any operation like
Insert/Update/Select/Delete or some business functions etc..
Stored procedures should be tested for functionality(business rules) in all
possible positive and negative scenarios.
Positive scenarios
Passing all required parameters with valid values with valid range of data,
data type.
Negative scenarios
Passing values with invalid data range(Boundary) as business rule
perspective
Testing Tables
Primary keys, foreign keys, nullability, default values, data types will be
tested.
E.g.: Insertion with passing values which will break foreign/primary key
relationship
Testing Process
An excel document with multiple sheets will be used to have these values
according to FSD(Functional Specification Document).This will be done
manually.
Later, query will be executed on database and compare with the excel
values.
ElectronicAddressDat Important
a.xls queries.docx
Logic: Data from Excel document will be loaded in to one dataset object.
Query will be used to fetch the actual data from database and kept into
another dataset object. Comparing these two datasets will give the result.
Total number of records will be checked or data can be compared with the
excel/XML data document.
Testing Functions
Before testing the function, both input and output should be known to QA.
Testing Triggers
Invoke the trigger using related operation insert/delete/update on particular
table and check the trigger functionality. If trigger inserts the data into any
history table, then check the data in that table.
Testing Views
View should be tested whether it holds the required columns from required
tables.
This is similar to testing table. Here, data type, length, nullability should be
checked.
Initiate the job either manually or through CSharp code and test the
functionality.
ExecuteQuery(sqlQuery, "MDMElectronicAddressODSConnString");
Check the job history whether jobs are executed as scheduled and successful.
Note: Jobs will take some time to execute. Execution time depends on
functionality and data.
Testing Replication
Replication is meant for transferring the data from one data source to other
data source. In most of the cases, it would be snap shot(one way) replication.
1) Insert the data in publisher(server+ database +table) and check the data
in subscriber based on latency.
This depends on many parameters like agent is not running at publisher/
subscriber or subscriber is down etc..
Some SPs and tables are required to trace SQL code coverage. One SP should
be executed in the first test case and other SP should be executed in the last test
case of SP which testing is required.
Performance Testing
This will be required when there are high volumes of data and many
transactions takes place in the application.
Security Testing
This ensures that only authenticated user can access the specified database
and server and executes operations based on login/user permissions.
Sometimes, passwords will be encrypted in the database.
2. Right click on project and new test of type "Database Unit Test"
By default, it would be 1(i.e. first result set).If there are multiple result sets,
give exact result set number
Sample Scenario: If Test SQL script output expects two result sets and second
result as empty.
Not Empty ResultSet: This condition will be used in testing, if result set is
expected in the output.
By default, it would be 1(i.e. first result set).If there are multiple result sets,
give exact result set number
Sample Scenario: If Test SQL script output returns two result sets. First result
set is empty and second result set is expected to have some records.
Row Count: This condition will be used to check number of records in the
given result set.
It associates with three properties apart from name of test condition.
By default, it would be 1(i.e. first result set).If there are multiple result sets,
give exact result set number
Sample Scenario: If Test SQL script output returns two result sets. First result
set is empty and second result set is expected to have 10 records.
Scalar Value: This condition is used to check individual field value in the
specified row number and result set.
By default, it would be 1(i.e. first result set).If there are multiple result sets,
give exact result set number
D)Expected Value:
Note: This is mostly used for checking numeric or Boolean values. This is case
sensitive check for text values.
Sample Scenario: If Test SQL script output returns two result sets. First result
set is empty and second result set is expected to have some records and 2nd row
and 2nd column should have value 100
Every test case can have "Pre-Test" and " Post-Test" scripts along with the
"Test" script.
Pre-Test: In general, this will be used to insert the test data or perform some
execution before testing.
If test case is on testing SP, then script with executing SPs will be used.
Post-Test: In general, this will be used to delete the test data or perform
some execution after testing.
2. Condition to check whether second result set is not empty as shown below.
3. Condition to check second result set with 2nd column in 2nd row value for
100 as shown below.
4. Condition to check second result set with 2nd column in 3rd row value for
200 as shown below.
5. Condition to check 1st column in 2nd row value for null as shown below.
Best Practices
1. Use optimized queries and hints wherever it is possible
9. Pair with novices with people that have database testing experience