We'll now check out some pgunit test examples as follows:
- This is the first test script to test whether there are any bank ATM ZIP codes not included in the ZIP coordinates table:
create or replace function pgunit.test_case_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.test_assertNull('Bank ZipCode is not included in Zip coordinates table', id); end;
$$ language plpgsql;
- After creating the first test by pgAdmin, please execute this query to proceed with the first test:
select * from pgunit.test_case_bank_zipcode();
- The result is as follows:
Figure 11.12 – Simple pgunit test 1
The first bank ATM location has zipcode = 1000 but as this value, 1000, does not exist in...