Test and Behavior Driven Development with MySQL, MariaDB Database

Overview of Test Driven Development

Test-Driven Development (TDD) is a software development process which includes test-first development. It means that the developer first writes a fully automated test case before writing the production code to fulfil that test and refactoring.


Test Driven Development With Database

Database Testing

Database testing requires that the tester should have knowledge in checking tables, writing queries and writing procedures, so to make tests effectively.

Testing can be performed in a web application or desktop because the database can be used in the application. Some points are given below to test the database -


Database Testing Checklist

To perform testing with Databases SQL queries are used to develop the tests. The most commonly used command is “Select” in the case when we are using SQL database.

Select * from <tablename> where <condition>

Apart from Select, SQL has 3 important types of commands -

We can develop our queries on the basis of above SQL commands.


Behaviour Driven Development - Structural Testing with Database

Structural testing includes testing the following components -


Testing Different Structural Components in SQL Database

When we working with databases to test transactions it is important to make sure that they satisfy the ACID properties.

These are the statements commonly used -

A database schema defines that how the data is going to be organized inside a Database. To test it, we identify the requirements based on which the database operates. Sample requirements -

We specify in our code when a certain action occurs on a table, a piece of code (a trigger) can be auto-instructed to be executed.

Stored procedures are more or less similar to user-defined functions. These can be invoked by Call Procedure/Execute Procedure statements and the output is usually in the form of result sets.These are also tested during -

In this, we check for the default value, unique value and foreign key. In the particular field constraint, we check that column should contain a unique value if it is set to the primary key and check that value in a column should not be other than the default value.


Unit Testing NoSql Database

We can test the database through various ways, if we are using SQL server then we can open the SQL server query analyzer and write queries to retrieve the data.

Unit Testing Using SQL Queries

Unit Testing Using UI (User Interface)

We can test this, that is going to relevant table at which we want to make insertions.

For example -

Things required to be covered under Database Testing -


Functional Testing for Database

In this, we firstly test each component to check that output is produced according to the code and then double checked to ensure that the rest of the system is not impacted by the output of this particular component.

It is particularly imperative that all cases of possible impact are carefully covered, including the edge case or boundary case scenarios. It mainly focuses on the accessibility, usability, and main function testing.

Example For Functional Testing -

In an application, performing an action like register new user adds data or changes data when we make updates or delete the user from our application. We can verify it the database by querying the tables directly.

But these changes can also be pulled by our application because data is already being pulled by the application and is displayed correctly (or incorrectly) in the application.

As an example, we refer to above example which is shown under

Testing with the help of integration of database with UI portion, for an example we can refer to this portion.


Database Testing Tools

Another way is available to test the database by using various testing tools which are available for Database Testing, for example -

If we want to do accurate testing then you should get first knowledge of database tables, structure. Once we are familiar with the database which we are going to test, then we can test the database more accurately and in more detail.

Testing Database as a Manual Tester

For automation database testing we will need to write a script.

Testing Database with respect to Specific Database (For Example - MYSQL )

Testing corresponding to SQL database is performed at the bottom of the database under the Demo portion. So for this, we can refer to Demo section, which is written especially for SQL Database.

Selenium WebDriver

 

Apache Jmeter

Apache JMeter may be used to test performance both on static and dynamic resources, Web dynamic applications. It can be used to simulate a heavy load on a server, group of servers, network or object to test its strength or to analyze overall performance under different load types.

Implementing Test Driven Development with Database

Installation Of SQL on LINUX

sudo apt-get install mssql-server=<version_number>

sudo systemctl start mssql-server

Unit Testing for Database using the SQL Database

create table month_value( eid int not null, m int, y int, v int );

insert into month_value(eid,m,y,v)values(1,12,2017,20);

create view cm_abs_month as select *, y * 12 + m as am from month_value;


select concat(
 'For every (y,m) there is value for (am): ',
 case when(select count(distinct y, m) from month_value) = (select count(distinct am) from cm_abs_month) then 'passed'
 else 'failed'
 end
);


Concluding Test Driven Development for Database

TDD refers to test the product while it is developed and we highly give the importance to feedback which we get after failing test rather than the passing test.

This feedback is used in both the cases to refactor the code and to minimize the changes that we have to make for the next time, but there is also a bottleneck for database testing that a lot of additional expenditure is added for the database testing.

It also requires the basic knowledge of SQL statements and specially DML(Data Manipulation Language) statements. Database testing plays an important role when integrated with the application.

The database acts as a client-server system. If any of the malfunctions appear it may cause system deadlock, data corruption, data loss and bad performance. So we cannot ignore the importance of Database Testing.


How Can Don Help You?

Don follows the Test Driven Development Approach in the development of Enterprise level Applications following Agile Scrum Methodology.