The code is distributed according to the Maven's Standard Directory Layout. This allows to developers (Particularly Java developers) to identify where each component is stored following the 'Convention over Configuration' pattern.

These instructions describe how to install the application from the source code.

Tools

The tools needed to develop db2unit are:

  • Maven - To test and deploy.
  • JDK (Java Development Kit) - To execute Maven.
  • Db2 - To test.
  • A database called db2unit.

First you have to retrieve the code from GitHub:

  • Via a "Clone or Download + Download ZIP" button (zip file download).
  • Via a git clone https://github.com/angoca/db2unit.
  • If you are using an IDE like Eclipse, you can use the Git plugin (egit) and put the URL of the command in the previous item.
  • Or just the sources, unconnected to git: https://github.com/angoca/db2unit/archive/master.zip

Once the sources are in the computer, there are many different ways to work with and to build a release.

If you have Maven, you can build the project and execute the scripts from there:

cd db2unit
mvn
cd target/db2unit/db2unit

If you use Eclipse or DataStudio you can import the sources in an Eclipse project (Java perspective). You have to include the source directory as build path (src/main, src/main/scripts, src/test, src/test/scripts) and then go to the bin directory in the shell to execute them.

If you have M2 (Maven plugin) in Eclipse, then configure the project by importing a Maven project. Finally, you only need to go to your bin directory to use the scripts.

If you do not have any of those tools, you have to change to the src/test/scripts directory.

Once you have decided a way to use the sources, 4 variables need to be defined in order to run the script to install, run examples and tests.

  • DB2UNIT_SRC_MAIN_CODE_PATH
  • DB2UNIT_SRC_MAIN_SCRIPT_PATH
  • DB2UNIT_SRC_TEST_CODE_PATH
  • DB2UNIT_SRC_TEST_SCRIPT_PATH

These variables are initialized via the init-dev script. However, they are always set based on the DB2UNIT_PATH variable according to the current position, thus you have to change the current directory where the tests scripts are located.

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

NOTE: There should exist the SYSTOOLSPACE tablespace before executing the tests, because one of the scripts uses ADMIN_DROP_SCHEMA.

CREATE TABLESPACE SYSTOOLSPACE IN IBMCATGROUP 
  MANAGED BY AUTOMATIC STORAGE USING STOGROUP IBMSTOGROUP
  EXTENTSIZE 4

Linux/UNIX/Mac OS:

cd src/test/scripts
. ./init-dev
. ../../main/scripts/install

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

Windows (CMD.exe - db2clp):

cd src\test\scripts
init-dev.bat
..\..\main\scripts\install.bat

Windows PowerShell

cd src\test\scripts
.\init-dev.ps1
..\..\main\scripts\install.ps1

After the install, all statements should have been successful.

Install & Run tests

There is a script that allows you to install all tests from a suite, and execute them. You can control the behavior according to its parameters. The tool exists for the three supported shells (bash, CMD.exe, PowerShell).

. ./allTest  -- Linux
allTest      -- Windows
.\allTest    -- Windows PowerShell

The parameters to control the execution are:

  • No parameters : The script executes the suites with pauses in between. It means, you have to press enter in each step.
  • -np : Executes the installed suites without pauses in between. This is useful for Benchmarking.

When no parameters are given, the script will install and execute the tests.

On the other hand, when -np is passed, it will measure the time for the complete execution (Start time, End time, Elapse time).

test

For each suite, this script calls another one to install or, install and execute. The other script is test and can be adapted for any tests suite. These are some examples:

. ./test ../sql-pl/TestLogs.sql x  -- Linux
test ..\sql-pl\TestLogs.sql i x    -- Windows
.\test ..\sql-pl\TestLogs.sql i    -- Windows PowerShell

This script receives three parameter: SCHEMA, OPTION_1 and OPTION_2.

  • The schema is the name of the suite to execute.
  • When i is one of the options, it means it will be installed.
  • When x is one of the options, it means that the suite will be executed.

If you want to check how does it work, you can check the Travis-CI execution output.

Examples

In a similar way to the tests, you can execute the examples. For more information, please visit the Running examples section.