Quickstart

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
Windows and Linux run the same commands. On Windows invoke 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:

  • 72 runnable pgTAP tests for the functions, one test_<routine>.sql each in unit_tests/unit/public/functions/
  • Behaviour tests for the 2 triggers in unit_tests/unit/public/triggers/
  • The HTML report and the JSON summary
  • The CI report bundle (JUnit, Cobertura, LCOV) in 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);"

Before you run

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.