db2unit

Danta

Download Tar file Download Zip file

db2unit is a testing framework for IBM Db2 written in SQL PL language. It is xUnit framework, that takes the same design as the well-known jUnit. db2unit could be considered as a jUnit porting for Db2 SQL-PL.

The licenses of this project are:

These are some useful links:

Author:

Andres Gomez Casanova (@AngocA)


Installation from released file

One variable needs to the specified in order to run the install and example scripts.

DB2UNIT_PATH

This variable is initialized via the init script.

Before installing the scripts in a database, a connection to it has to be established. If not, an error will be raised.

Linux/UNIX/MAC OS:

Just follow these steps:

tar -zxf db2unit.tar.gz
cd db2unit
. ./install

Make sure to put the dot before the command. This will source the values and use the current connection.

Windows Terminal (CMD - db2clp):

First, unzip the file db2unit.zip, and then:

cd db2unit
install.bat

Windows PowerShell:

First, unzip the file db2unit.zip, and then:

cd db2unit
.\install.ps1

====

After the install, all statements should have been successful.

A more detailed guide to install the utility can be found in the Install section of the wiki: https://github.com/angoca/db2unit/wiki/Install

You can also install the utility from the sources and run the examples and tests: https://github.com/angoca/db2unit/wiki/Install%20from%20sources


Usage

1. Write the test suite

Let's suppose you work on a schema called MY_SCHM. From now on, the schema name will refer to the name of the test suite. It means, your test suite is also called MY_SCHM.

Your tests suite could have the following fixtures that helps to prepare the environment:

-- Test fixtures
CREATE OR REPLACE PROCEDURE ONE_TIME_SETUP()
 BEGIN
  -- Your code
 END @

CREATE OR REPLACE PROCEDURE SETUP()
 BEGIN
  -- Your code
 END @

CREATE OR REPLACE PROCEDURE TEAR_DOWN()
 BEGIN
  -- Your code
 END @

CREATE OR REPLACE PROCEDURE ONE_TIME_TEAR_DOWN()
 BEGIN
  -- Your code
 END @

You create your tests in the same schema as your fixtures. All of these stored procedures will be your tests suite. The name of our tests should starts by TEST_ and they should not have any argument, like this:

CREATE OR REPLACE PROCEDURE TEST_my_first_test()
 BEGIN
  -- Your code using the test functions.
  ASSERT_STRING_EQUALS(EXPECTED, ACTUAL);
 END @

In the previous test, you compared two strings. You can use other types of assertions. Please visit the API section: https://github.com/angoca/db2unit/wiki/API

The fixtures and the tests should be created under the same schema, in order to be part of the same suite.

2. Execute your tests suite

Once you have created your procedures in the database, you can run the tests suite like this:

CALL DB2UNIT.RUN_SUITE('MY_SCHM')

Once the execution is finished, you will see a report of the execution.

Check the Usage section for more information about the framework. https://github.com/angoca/db2unit/wiki/Usage


FILES AND DIRECTORIES

These are the files included in the released version:

The * in the install-related files means that several files for each name can be found:

For more information please visit: