We'll check out some pgunit test examples as follows:
- This is the PGUnit script for the same first test of checking whether there are any bank ATM ZIP codes that are not included in the ZIP coordinate table:
create or replace function pgunit.__test_bank_zipcode() returns void as $$
declare
id INT;
begin
select "ATM locations"."ID" from "ATM locations" where "ATM locations"."ZipCode" NOT IN (select "Zip coordinates".zip from "Zip coordinates") LIMIT 1 INTO id;
perform pgunit.assert_null(id, 'Bank ZipCode is not included in Zip coordinates table');
end;
$$ language plpgsql;
- After creating the first test in pgAdmin, we can execute the following query to run the first test:
select * from pgunit.__test_bank_zipcode();
- Because the first ATM location has zipcode = 1000, which does not exist in the ZIP coordinates table, an exception is raised with our defined message: Bank ZipCode...