UnitAutogen documentation

UnitAutogen is a single executable, unitautogen. You point it at a PostgreSQL database and it reads your functions and triggers, writes the tests, runs them and reports coverage, with no test written by hand. The tests it produces are standard pgTAP, so they run with SELECT runtests(...) or pg_prove like tests you would write yourself.

It works with any PostgreSQL 14 to 18, self-hosted or managed. That includes Supabase, Neon, Amazon RDS and Aurora, and Azure Database for PostgreSQL, wherever you can enable the pgTAP and plpgsql_check extensions. These pages apply to version 0.5.0-beta.

The five commands

Each command has its own page with what it does, its command line, the report it writes and where its files go. Every command shares the same basic options and prints one line per routine plus a summary.

CommandWhat it doesEdition
unit tests
unitautogen --schema public
Unit tests and branch and statement coverage for your functions and triggers. No command word needed.Community
integration
unitautogen integration --schema public
Every routine run for real, together with the functions it calls and the triggers its writes fire.Team
seccover
unitautogen seccover --schema public
The full security review of functions, views, triggers, RLS policies and column-level security.Enterprise
pii
unitautogen pii --schema public
Personal data leaked through error and RAISE messages. On by default inside seccover.Enterprise
hipaa
unitautogen hipaa --schema public
Runs seccover, adds the audit-log check and writes a stamped HIPAA report.Enterprise

Inside a Supabase project, add --supabase to any of them. See Supabase mode. To add or correct the PHI, personal-data and audit tables the tool detects, keep a unitautogen.toml next to your code. See The config file.

The one guarantee

UnitAutogen never gives you a fabricated, false-passing or flaky test. Every generated test is re-run on a clean pass before it is kept. A branch that cannot be driven soundly is reported as NOT_TESTABLE with a plain reason, never faked. So every report shows 0 failed and 0 false tests.

What's new in 0.5.0-beta

  • Multi-column foreign keys are seeded correctly in every command. Each composite key gets one matching parent row, parents first, so routines and triggers over those tables now get their tests and coverage.
  • More column types work as keys and values, including sized char and varchar, uuid, domains with CHECK, arrays, bit(n), bytea, money, ltree, hstore, inet and cidr, ranges, composite types, generated columns and quoted mixed-case names.
  • More branches are reached, through values returned in a called function's OUT and INOUT parameters, chains of local variables, date differences, NOT IN with a NULL, and divide by zero.
  • More error handlers are reached, for foreign-key violations on DELETE, NOT NULL, UNIQUE on the real key, and bad xml, json or base64 input. A handler test is named for the handler that really ran, or marked not reached.
  • seccover judges more schemas, with self-referencing foreign keys, CHECK (col IS NOT NULL), unique indexes without a primary key, generated columns and the column types above.
  • DATABASE_URL is read as a connection string, and an unreachable database gives a clear CANNOT CONNECT message and exit code 4. See Connecting.