GithubHelp home page GithubHelp logo

pgtest's Introduction

PgTest

Testing in PostgreSQL.

Installation

Create database and execute pgtest.sql. This will create pgtest schema with functions that are used for testing.

Usage

Create schema for your tests:

CREATE SCHEMA IF NOT EXISTS test;

Create test functions. Test function MUST return void:

CREATE OR REPLACE FUNCTION test.a_equals_a_ok()
  RETURNS void AS
$$
BEGIN
  PERFORM pgtest.assert_equals('A', 'A');
END
$$ LANGUAGE plpgsql
  SECURITY DEFINER
  SET search_path=test, pg_temp;
CREATE OR REPLACE FUNCTION test.a_equals_b_fails()
  RETURNS void AS
$$
BEGIN
  PERFORM pgtest.assert_equals('A', 'B');
END
$$ LANGUAGE plpgsql
  SECURITY DEFINER
  SET search_path=test, pg_temp;

Run tests:

SELECT pgtest.run_tests('test');

Result is number of messages that failed. Raised messages show more specific info about tests - what tests running, how many failed, what was the cause and how long it took. If you do not want to see pg_exception_context in messages then change client_min_messages to NOTICE:

SET client_min_messages TO NOTICE;

Assertions

  • pgtest.assert_equals(expected_value, real_value);
  • pgtest.assert_not_equals(not_expected_value, real_value);
  • pgtest.assert_true(boolean_value);
  • pgtest.assert_false(boolean_value);

expected_value and real_value must be same type (BIGINT, BIT, BOOLEAN, CHAR, VARCHAR, DOUBLE PRECISION, INT, REAL, SMALLINT, TEXT, TIME, TIMETZ, TIMESTAMP, TIMESTAMPTZ, XML).

pgtest's People

Contributors

raitraidma avatar

Watchers

Ahti Kitsik avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.