pgTAP is a PostgreSQL extension that lets you write unit tests for your database schema, functions, and policies.
Setup with Supabase
pgTAP is built into Supabase. Tests go in supabase/tests/*.sql.
# Run all testssupabase test db# Run with specific testsupabase test db --filter "schema_basics"
Writing Tests
BEGIN;SELECT plan(5); -- Number of assertions-- Table existsSELECT has_table('public', 'users', 'users table exists');-- Column checksSELECT has_column('public', 'users', 'email', 'has email column');SELECT col_not_null('public', 'users', 'email', 'email is NOT NULL');SELECT col_is_pk('public', 'users', 'id', 'id is primary key');-- RLS is enabledSELECT row_level_security_is_enabled('public', 'users', 'RLS on users');SELECT * FROM finish();ROLLBACK; -- Clean up test state