Welcome to the pgUnitTest Project Home Page

The pgUnitTest project is a PostgreSQL Community project that is a part of the pgFoundry.

pgFoundry page (for download and news):

Project description

Short description

pgUnitTest is a command line tool written in Java. Its goal is to execute a set of queries that must return an expected result. If the real result and the expected result match then the unit test successes, else it fails. pgUnitTest can also be used as a random data generator to insert a lot of data into test tables.

Detailed description

The goal of this project is to build a software able to complete unit tests on a set of queries or stored procedures for PostgreSQL. This means:

The program that runs those tests is a command line program. Test description is done in a XML file that is loaded with the command line. In order to make the test description easier a little scripting language is available. As an example:

      SELECT name, surname FROM the_table WHERE age < 20;
   CHECK –i
      name, surname
      (Alfred, Newman)
      (John, Smith);

We can see the '-i' option, meaning: case insensitive. Other options can be: -l or -g, depending on the test type:

An example of insert unit test is:

      FOR 1..1000 {
         INSERT INTO MY_TABLE VALUES ('%{integer(5, 5000, 0, true)}%',
         '%{string("[a-z]{5,10}", 10)}%',
         '%{dictionary(mydict.txt, 0)}%',
         '%{reference(other_table, column, 5)}%');

This uses a special syntax in order to use random data generators and insert a lot of data with a FOR loop statement. This is also helpful to fill in a database in order to do other tests than unit tests.

In the example above the query insert 1000 times:

In the script or in the XML file there is an option to tell the interpreter if PostgreSQL must rollback or not after the set of unit tests.

We can provide a set of tests. There is a result file containing the result for each test:

This result file is in XML but on the command line we can specify to convert it to text or HTML or insert the results into a database.

An example of use is:

pgUnitTest -i script.pgu -o report.html -f html

This was an example where we provided:

The XML output can be reused in order make a difference between outputs:

pgUnitTest -d file1.xml file2.xml file3.xml ... –o result.html

This example shows how to make a diff between results to see differences. It is useful to compare different tests.


Powered By GForge Collaborative Development Environment