Skip to content

Instantly share code, notes, and snippets.

@knmkr
Last active August 29, 2015 14:20
Show Gist options
  • Save knmkr/45c08bbaecc3aabec08a to your computer and use it in GitHub Desktop.
Save knmkr/45c08bbaecc3aabec08a to your computer and use it in GitHub Desktop.
[postgresql] Unit testing in PostgreSQL with pgTAP extension

PostgreSQL の ユニットテストフレームワーク pgTAP を使ってみる.

ドキュメント通りインストールする.

コンパイル:

$ wget http://api.pgxn.org/dist/pgtap/0.95.0/pgtap-0.95.0.zip
$ ./pgtap-0.95.0
$ cd pgtap-0.95.0
$ make
$ make installcheck
$ make install

CREATE EXTENSION する:

$ psql my_database
psql (9.4.1)
Type "help" for help.

my_database=# CREATE EXTENSION pgtap;
CREATE EXTENSION

pass するテスト:

my_database=# BEGIN;
my_database=# SELECT plan(1);
my_database=# SELECT ok( 9 < 10, 'simple comparison' );
            ok
--------------------------
 ok 1 - simple comparison
(1 row)

my_database=# ROLLBACK;

fail するテスト:

my_database=# BEGIN;
my_database=# SELECT plan(1);
my_database=# SELECT ok( 9 > 10, 'simple comparison' );
                  ok
--------------------------------------
 not ok 1 - simple comparison        +
 # Failed test 1: "simple comparison"
(1 row)

my_database=# ROLLBACK;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment