Generate unit tests and a coverage report for every function and trigger in the public schema. Generating unit tests is the default action, so you do not type a command word.
unitautogen --schema public --out unit_tests --html report.html --json report.json
unitautogen.exe; on Linux invoke ./unitautogen (or add its folder to PATH to drop the ./). Each release comes in a folder named for the system and version, such as dist-Windows-0.5.0-beta and dist-Linux-0.5.0-beta. The executable inside is already named unitautogen.exe or unitautogen, so put that folder on your PATH.You will see one line per routine, one line per trigger, and a summary. Real output from a sample database:
public.account_health: 14 tests kept, branch 100% / stmt 100% [test_account_health.sql]
public.accrue_interest: 15 tests kept, branch 100% / stmt 100% [test_accrue_interest.sql]
public.apply_overdraft_fee: 12 tests kept, branch 100% / stmt 100% [test_apply_overdraft_fee.sql]
public.close_account: 9 tests kept, 1 pruned -> NT, branch 100% / stmt 100% [test_close_account.sql]
public.post_entry: 7 tests kept, 1 pruned -> NT, branch 100% / stmt 100% [test_post_entry.sql]
public.transfer_funds: 15 tests kept, 1 pruned -> NT, branch 100% / stmt 100% [test_transfer_funds.sql]
[OK ] public.account :: audit_balance 2/2 [update:wrote, update:absent]
[OK ] public.journal_line :: require_linked_account 3/3 [insert:threw, insert:rows, insert:rows]
triggers: 2 (2 behaviour-driven, 0 skipped), 5 behavioural assertions, 0 fail, 0 skip
== done: 72 tests across 6 routines, avg branch 100.0% -> unit_tests/ ==
That single command produced:
test_<routine>.sql each in unit_tests/unit/public/functions/unit_tests/unit/public/triggers/unit_tests/unit/A "1 pruned -> NT" note is the guarantee at work. A test that would not pass cleanly is dropped and the branch reported honestly, never faked.
Run the generated tests yourself at any time:
psql -d mydb -c "SELECT * FROM runtests('test_transfer_funds'::name);"
Point the tool at a throwaway copy of your database, never production, and make sure pgTAP and plpgsql_check are installed there. See Prerequisites and Connecting. On a Supabase project, use Supabase mode instead.