All Projects → mixerp → Plpgunit

mixerp / Plpgunit

Licence: other
PostgreSQL Unit Testing Framework

Labels

Projects that are alternatives of or similar to Plpgunit

Docker Postgis
This repository contains Docker image builds for PostgreSQL / PostGIS
Stars: ✭ 62 (-39.22%)
Mutual labels:  plpgsql
R Server Hospital Length Of Stay
Hospital length of stay prediction solution with Microsoft R Server
Stars: ✭ 76 (-25.49%)
Mutual labels:  plpgsql
Pg permission
A simple set of views to see ALL permissions in a PostgreSQL database
Stars: ✭ 92 (-9.8%)
Mutual labels:  plpgsql
Basketball
Public subset of my basketball github
Stars: ✭ 65 (-36.27%)
Mutual labels:  plpgsql
Openmaptiles
OpenMapTiles Vector Tile Schema Implementation
Stars: ✭ 1,175 (+1051.96%)
Mutual labels:  plpgsql
Evergreen
Evergreen ILS
Stars: ✭ 85 (-16.67%)
Mutual labels:  plpgsql
Pg Clone Schema
Postgres clone schema utility without need of going outside of database. Makes developers life easy by running single function to clone schema with all objects. It is very handy on Postgres RDS. Utility is sponsored by http://elephas.io/
Stars: ✭ 59 (-42.16%)
Mutual labels:  plpgsql
Periods
PERIODs and SYSTEM VERSIONING for PostgreSQL
Stars: ✭ 101 (-0.98%)
Mutual labels:  plpgsql
Openquerystore
OpenQueryStore
Stars: ✭ 75 (-26.47%)
Mutual labels:  plpgsql
Pg Semver
A semantic version data type for PostgreSQL
Stars: ✭ 91 (-10.78%)
Mutual labels:  plpgsql
Ora migrator
Tools for Oracle to PostgreSQL migration
Stars: ✭ 66 (-35.29%)
Mutual labels:  plpgsql
Pg bitemporal
Bitemporal tables in Postgres
Stars: ✭ 70 (-31.37%)
Mutual labels:  plpgsql
Cartodb Postgresql
PostgreSQL extension for CartoDB
Stars: ✭ 90 (-11.76%)
Mutual labels:  plpgsql
Code Or Die
Code or Die: A Game for Galactical Domination
Stars: ✭ 63 (-38.24%)
Mutual labels:  plpgsql
Qt Client
This repository contains the source code for the Desktop client. The Desktop client is built using the Qt framework for C++. The client can be extended or customized using JavaScript. This client is used by all editions of xTuple ERP.
Stars: ✭ 93 (-8.82%)
Mutual labels:  plpgsql
Pg
PostgreSQL experiments
Stars: ✭ 60 (-41.18%)
Mutual labels:  plpgsql
Ssis Queries
A set of queries useful to easily extract monitoring and package performance data from SSISDB database
Stars: ✭ 79 (-22.55%)
Mutual labels:  plpgsql
Civicscape
A new standard for real-time policing.
Stars: ✭ 101 (-0.98%)
Mutual labels:  plpgsql
Totp
RFC6238 TOTP implementation in pure PostgreSQL plpgsql
Stars: ✭ 98 (-3.92%)
Mutual labels:  plpgsql
Postgresql Anyarray
PostgeSQL extension adding highly desirable, data-type independent array functionality.
Stars: ✭ 91 (-10.78%)
Mutual labels:  plpgsql

#PostgreSQL Unit Testing Framework (plpgunit)

Plpgunit started out of curiosity on why a unit testing framework cannot be simple and easy to use. Plpgunit does not require any additional dependencies and is ready to be used on your PostgreSQL Server database.

#Documentation Please visit the wiki page.

Creating a Plpgunit Unit Test

A unit test is a plain old function which must:

  • not have any arguments.
  • always return "test_result" data type.

#First Thing First However you could do that, but there is no need to call each test function manually. The following query automatically invokes all unit tests that have been already created:

BEGIN TRANSACTION;
SELECT * FROM unit_tests.begin();
ROLLBACK TRANSACTION;

Remember, if your test(s) does not contain DML statements, there is no need to BEGIN and ROLLBACK transaction.

#Examples View documentation for more examples.

Example #1

DROP FUNCTION IF EXISTS unit_tests.example1();

CREATE FUNCTION unit_tests.example1()
RETURNS test_result
AS
$$
DECLARE message test_result;
BEGIN
	IF 1 = 1 THEN
		SELECT assert.fail('This failed intentionally.') INTO message;
		RETURN message;
	END IF;

	SELECT assert.ok('End of test.') INTO message;	
	RETURN message;	
END
$$
LANGUAGE plpgsql;

--BEGIN TRANSACTION;
SELECT * FROM unit_tests.begin();
--ROLLBACK TRANSACTION;

Will Result in

Test completed on : 2013-10-18 19:30:01.543 UTC. 
Total test runtime: 19 ms.

Total tests run : 1.
Passed tests    : 0.
Failed tests    : 1.

List of failed tests:
-----------------------------
unit_tests.example1() --> This failed intentionally.

Example #2

DROP FUNCTION IF EXISTS unit_tests.example2()

CREATE FUNCTION unit_tests.example2()
RETURNS test_result
AS
$$
DECLARE message test_result;
DECLARE result boolean;
DECLARE have integer;
DECLARE want integer;
BEGIN
	want := 100;
	SELECT 50 + 49 INTO have;

	SELECT * FROM assert.is_equal(have, want) INTO message, result;

	--Test failed.
	IF result = false THEN
		RETURN message;
	END IF;
	
	--Test passed.
	SELECT assert.ok('End of test.') INTO message;	
	RETURN message;	
END
$$
LANGUAGE plpgsql;

--BEGIN TRANSACTION;
SELECT * FROM unit_tests.begin();
--ROLLBACK TRANSACTION;

Will Result in

Test completed on : 2013-10-18 19:47:11.886 UTC. 
Total test runtime: 21 ms.

Total tests run : 2.
Passed tests    : 0.
Failed tests    : 2.

List of failed tests:
-----------------------------
unit_tests.example1() --> This failed intentionally.
unit_tests.example2() --> ASSERT IS_EQUAL FAILED.

Have -> 99
Want -> 100

Example 3

DROP FUNCTION IF EXISTS unit_tests.example3();

CREATE FUNCTION unit_tests.example3()
RETURNS test_result
AS
$$
DECLARE message test_result;
DECLARE result boolean;
DECLARE have integer;
DECLARE dont_want integer;
BEGIN
	dont_want := 100;
	SELECT 50 + 49 INTO have;

	SELECT * FROM assert.is_not_equal(have, dont_want) INTO message, result;

	--Test failed.
	IF result = false THEN
		RETURN message;
	END IF;
	
	--Test passed.
	SELECT assert.ok('End of test.') INTO message;	
	RETURN message;	
END
$$
LANGUAGE plpgsql;

--BEGIN TRANSACTION;
SELECT * FROM unit_tests.begin();
--ROLLBACK TRANSACTION;

Will Result in

Test completed on : 2013-10-18 19:48:30.578 UTC. 
Total test runtime: 11 ms.

Total tests run : 3.
Passed tests    : 1.
Failed tests    : 2.

List of failed tests:
-----------------------------
unit_tests.example1() --> This failed intentionally.
unit_tests.example2() --> ASSERT IS_EQUAL FAILED.

Have -> 99
Want -> 100

Need Contributors for Writing Examples

We need contributors. If you are interested to contribute, let's talk:

https://www.facebook.com/binod.nirvan/

Happy testing!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].