An Introduction to Database Testing With an Example of MariaDB

Written by sergeishaikin | Published 2022/07/23
Tech Story Tags: software-testing | database | software-qa | mariadb | quality-assurance | databases | relational-database | databases-best-practices

TLDRMariaDB Server is one of the most popular open-source relational databases. We need to install it in debug mode on our PC to test DataBase. The installation will take a few minutes, depending on your internet connection. Let’s create our first test with the next code: Test 00001: avarage --echo create table t1 ( pk int primary key, height int), calculate average (1,5), (2,4) and (3) with rows and (0,9)via the TL;DR App

Introduction

If we are talking about software testing then as testers, we all know how to test services with DataBase. But DataBase is also some kind of service and should be tested. Maybe you are wondering - How to test DataBase? Simple.

And today I'll talk about it based on the example of MariaDB Server, one of the most popular open-source relational databases.

Installation

Before starting our testing we consider how to install MariaDB properly. Because usual installation from the .exe file using Windows installer is not useful for performing any kind of testing. We need to install it in debug mode. I'd like to explain that on the Windows platform which is the most popular in the world.

You need to have three things:

  • Visual C++ (while installing Visual Studio, make sure to add "Desktop Development with C++"),
  • CMake
  • Git

Then you have all those three components on your PC, you will be able to start directly installation. Create a folder for MariaDB. Move to it.

On the command prompt, switch to your source directory, then execute:

mkdir Test
cd Test
git init
git clone -b mariadb-10.5.15 https://github.com/MariaDB/server.git

Now you downloaded the source code from the repository.

And then you need to move to the server folder, create a new folder bld and move to it:

cd server
mkdir bld
cd bld

We prepare almost all staff and we’ll perform CMake as a cross-platform build system generator using the next command:

cmake ..

The build is finished:

The final step will be building Debug version. The installation will take a few minutes. It depends on your internet connection.

cmake --build . --config Debug

Testing

And now is the really exciting part of our article. Let’s create our first test. It’s not so easy, but also not so hard as it seems. Some rules you should know.

You should use the extension .test then you are saving your test and put it in the folder c:\Test\server\mysql-test\main

But running out of our tests we will in the next path: c:\Test\server\bld\mysql-test

Because the main executed file is in that way.

Open notepad and write our first test with the next code:

--echo # 
--echo # Test #00001: avarage 
--echo # 
create table t1 ( 
  pk int primary key, 
  height int 
); 
insert into t1 values 
(0,9), 
(1,5), 
(2,4); 
show create table t1; 
select avg(height) from t1;  
drop table t1;

Now we should save this file with extension .test in my way, it will be sergei.test

In that test, we are creating a table with three rows and calculating the average height.

Let’s run our test:

mysql-test-run.pl sergei.test

Our test passed because no error in MariaDB and no error in the test script.

Sometimes we need to record our results. Simple. Just run the test with the record option:

mysql-test-run.pl sergei.test --record

It will create another file with an extension .result in the same directory as the test file with the same name. In my case it is sergei.result

Conclusion

There are many options to run our tests even a debug mode and control the process. All those descriptions you can find in Knowledge Base on the official site MariaDB.


Written by sergeishaikin | I'm software tester. And I like backend testing.
Published by HackerNoon on 2022/07/23